如何获取整个ListView的String-Array

时间:2015-01-23 10:15:36

标签: android arrays string listview android-listview

我有一个动态添加ListView的{​​{1}},如何在TextViews中获取TextView的所有ListView个对象? 对于测试,我想在String-Array方法中的String-Array中显示整个Toast

的onCreate:

onItemClick

final ListView sessionLv = (ListView) findViewById(R.id.session_list); sessionLv.setAdapter(sessionAdapter); sessionLv.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { TextView c = (TextView) view.findViewById(R.id.stepTime); String playerChanged = c.getText().toString(); Toast toast = Toast.makeText(getApplicationContext(), playerChanged +" wurde angeklickt!", Toast.LENGTH_SHORT); toast.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, 0); toast.show(); } });

中动态添加的adapter个对象的TextView
ListView

1 个答案:

答案 0 :(得分:1)

希望这会有所帮助,

//in your item click
sessionLv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        SessionItemAdapter adapter = (SessionItemAdapter) parent.getAdapter();
        List<String> allPlayers = adapter.getAllPlayers();

        // Log your list or whatever you want to do with it
        Log.i(TAG, "allPlayers: " + allPlayers.toString());

    }
});
//in your adapter getAllPlayers() would be something like this
public List<String> getAllPlayers(){
    List<String> list=new ArrayList<String>();
    for (Map item : values) {           
        int beepStringId = context.getResources().getIdentifier("exercise_typ_" 
        + item.get("type"), "string", context.getPackageName());
        String str = context.getResources().getString(beepStringId);
        list.add(str);
    }
    return list;
}