我有一个动态添加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
答案 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;
}