本文介绍了机器人:列表视图定制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能有一个单一的列表视图2个或多个列,用于与寻呼财产(即在同一时间列表视图将只显示4单列和preSS项目的右箭头,它会显示未来的4项)..
能否请你告诉我的程序来实现它,或者任何想法?
谢谢
普尼特

Is it possible to have a single listview with 2 or more columns, operable with paging property (i.e. at a time listview will show only 4 items in single column and on press of right arrow it will show next 4 items )..
Can you please tell me the procedure to implement it or any idea?
Thanks
puneet

推荐答案

不知道这是你要找的是什么,但基本上这code创建对象的基础上,你所使用的主要数据集的一个子集来填充列表。它是这样的:

Not sure if this is what you're looking for, but basically this code creates a subset of objects based on the main dataset you're using to populate your list. It goes something like this:

import android.app.ListActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;

public class MainActivity extends ListActivity {

// Constant for limiting array to match desired number of values in column
private final int NUMBER_OF_ITEMS_IN_COLUMN = 4;

// Index for starting point of array subset
private int mStartingIndex = 0;

// Data set array for list
private String[] mDataSet = new String[]{
    "One", "Two", "Three", "Four", "Five",
    "Six","Seven","Eight", "Nine", "Ten",
    "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen",
    "Sixteen", "Seventeen", "Eightteen", "Nineteen", "Twenty",
 };

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    changeListViewModel(0);
}

private void changeListViewModel(int startingIndex) {

 // Check staring index meets certain criteria
 if(startingIndex < 0)
  startingIndex = 0;
 else if(startingIndex >= mDataSet.length)
  startingIndex -= NUMBER_OF_ITEMS_IN_COLUMN;

 // Set starting and ending index
 mStartingIndex  = startingIndex;
 int endingIndex = startingIndex + NUMBER_OF_ITEMS_IN_COLUMN;

 // Make sure ending index isn't outside the bounds of the data set array
 if(endingIndex > mDataSet.length) endingIndex = mDataSet.length;

 // Create subset and set listview adapter
 String[] subSet = getDataSubset(startingIndex, endingIndex);
 setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, subSet));
}

private String[] getDataSubset(int startingIndex, int endingIndex){

 String[] toRet = new String[endingIndex - startingIndex];

 int index = -1;
 for(int x = startingIndex; x < endingIndex; x++)
  toRet[++index] = mDataSet[x];

 return toRet;
}

/*
 * Called from layout main.xml file
 */
public void backButtonClicked(View v) {
 changeListViewModel(mStartingIndex - NUMBER_OF_ITEMS_IN_COLUMN);
}


/*
 * Called from layout main.xml file
 */
public void nextButtonClicked(View v) {
 changeListViewModel(mStartingIndex + NUMBER_OF_ITEMS_IN_COLUMN);
}
}

这是pretty的基础,但它应该能够让你的开始。另外,使用这样的事情,你也可以通过具有返回对象的列表作为列表视图的一个子集数据库类配合列表视图与SQLite数据库。

It's pretty basic, but it should be able to get your started. Plus, using something like this, you could also tie in the listview with a SQLite database by having a database class that returns a list of objects as a subset for the listview.

您可以下载源在这里:下载源码

You can download the source here: Download Source

这篇关于机器人:列表视图定制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-04 21:19