Android 多个列表视图?
我正在尝试显示我正在创建的游戏的高分,有两列,一列显示他们的名字,另一列显示他们完成游戏所需的移动量 目前,它全部存储在SQLiteDatabase中,并以列表视图的形式显示,在列表视图中,它以一列的格式显示 名字,动作 但是我想在屏幕的另一面进行移动,这需要多个列表视图,还是需要编辑一个列表视图,或者它的适配器 目前使用的代码是:Android 多个列表视图?,android,sql,sqlite,android-listview,Android,Sql,Sqlite,Android Listview,我正在尝试显示我正在创建的游戏的高分,有两列,一列显示他们的名字,另一列显示他们完成游戏所需的移动量 目前,它全部存储在SQLiteDatabase中,并以列表视图的形式显示,在列表视图中,它以一列的格式显示 名字,动作 但是我想在屏幕的另一面进行移动,这需要多个列表视图,还是需要编辑一个列表视图,或者它的适配器 目前使用的代码是: datasource = new HighScoreDataSource(this); datasource.open(); //Open
datasource = new HighScoreDataSource(this);
datasource.open(); //Open the connection
List<HighScore> values = datasource.getAllHighScores(); //Retrieve all the data
//Using a simple cursor adapted to show the elements
ArrayAdapter<HighScore> adapter = new ArrayAdapter<HighScore>(this, android.R.layout.simple_list_item_1, values);
setListAdapter(adapter);
datasource=新的HighScoreDataSource(此);
datasource.open()//打开连接
列表值=datasource.getAllHighScores()//检索所有数据
//使用适于显示元素的简单光标
ArrayAdapter=新的ArrayAdapter(这是android.R.layout.simple\u list\u item\u 1的值);
setListAdapter(适配器);
用两个文本视图创建一个行布局
按您想要的方式放置,并实现一个简单的自定义阵列适配器
:
public class CustomAdapter extends ArrayAdapter<HighScore> {
private LayoutInflater inflater;
public CustomAdapter(Context context, int textViewResourceId,
List<HighScore> objects) {
super(context, textViewResourceId, objects);
inflater = LayoutInflater.from(context);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = inflater.inflate(R.layout.new_row_layout, parent, false);
}
HighScore item = getItem(position);
TextView name = (TextView) findViewById(R.id.name_id_textview);
name.setText(/*get the name from the item HighScore object*/);
TextView moves = (TextView) findViewById(R.id.moves_id_textview);
moves.setText(/*get the moves from the item HighScore object*/);
return convertView;
}
}
公共类CustomAdapter扩展了ArrayAdapter{
私人充气机;
公共CustomAdapter(上下文上下文,int textViewResourceId,
列出对象){
超级(上下文、textViewResourceId、对象);
充气器=充气器。从(上下文);
}
@凌驾
公共视图getView(int位置、视图转换视图、视图组父视图){
if(convertView==null){
convertView=充气机。充气(R.layout.new_row_layout,parent,false);
}
高分项目=获取项目(位置);
TextView name=(TextView)findViewById(R.id.name\u id\u TextView);
name.setText(/*从item HighScore对象获取名称*/);
TextView移动=(TextView)findViewById(R.id.moves\u id\u TextView);
moves.setText(/*从item HighScore对象获取移动*/);
返回视图;
}
}
另一个选项是在HashMaps
列表中打断列表值(包含两个条目,一个用于名称,一个用于移动),并使用(与上面的行布局相同)