0

作成中のゲームのハイスコアを表示しようとしています。1 つは名前、もう 1 つはゲームを完了するのにかかった移動量の 2 つの列で表示します。

現在、それはすべて SQLiteDatabase に保存され、リスト ビューに表示されます。ここでは、形式の 1 つの列として表示されます

名前、動き

しかし、画面の反対側に移動したいのですが、これには複数のリストビューが必要ですか、それとも1つのリストビューまたはそのアダプターの編集が必要ですか?

現在使用されているコードは次のとおりです。

        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);
4

1 に答える 1

0

2 つを好きなように配置して行レイアウトを作成しTextViews、単純なカスタムを実装しますArrayAdapter

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;
    }       

}

もう 1 つのオプションは、 (名前用と移動用の 2 つのエントリを含む)List<HighScore> valuesのリストで分割し、 (上記の行レイアウトで) を使用することです。HashMapsSimpleAdapter

于 2012-05-21T17:11:16.363 に答える