2012-05-21 4 views
0

나는 만들고있는 게임에 대해 높은 점수를 표시하려고합니다. 두 개의 열, 이름 및 게임을 완료하는 데 필요한 이동량에 대한 것입니다.여러 목록보기?

현재 그것은 모두의 SQLiteDatabase에 저장하고 형식

이름에 하나 개의 컬럼으로 표시 목록보기, 제시,

를 이동하지만 난의 움직임을 좀하고 싶습니다있다 화면 반대편에 여러 개의 목록보기가 필요하거나 하나의 목록보기 또는 해당 어댑터를 편집해야 할 필요가 있습니까?

현재 사용되는 코드는 다음과 같습니다

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

답변

0

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

} 

또 다른 옵션은 List<HighScore> values을 파괴하는 것입니다 HashMaps (이름과 이동에 대한 항목이 두 개인 항목)에 SimpleAdapter (위의 행 레이아웃 포함)을 사용하십시오.

관련 문제