filtresinden sonra tıklandığında doğru pozisyonu almaz. İşte benim kodum. Konu adını, konu kodlarını ve konu sonuçlarını bir arraylist’e koydum. Sorun şu ki, örneğin A (Pozisyon 0), B (Pozisyon 1) ve C (Pozisyon 2). Ben B aramak ve onu tıkladığında bu uygulama çok takdir A.Listview ile arama ve onclick,
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_c);
ctopics = (ListView) findViewById(R.id.clistView);
csearch = (EditText) findViewById(R.id.CSearch);
ctitle = new ArrayList<Ctitle>();
ctopics.setAdapter(cAdapter);
ctitle.add(new Ctitle("Swap Two Numbers",
"#include <iostream>\nusing namespace std;\nint main(){\nint a = 5, b = 10, temp;\ncout << ''Before swapping.'' << endl;\ncout << ''a = '' << a << '', b = '' << b << endl;\n\ntemp = a;\na = b;\nb = temp;\n\ncout << ''\nAfter swapping.'' << endl;\ncout << ''a = '' << a << '', b = '' << b << endl;\n\nreturn 0;\n}",
"Before swapping.\na = 5, b = 10\n\nAfter swapping.\na = 10, b = 5"));
ctitle.add(new Ctitle("While Loop",
"#include <iostream>\nusing namespace std;\nint main(){\nint a = 10;\nwhile(a < 15){\ncout << ''value of a: '' << a << endl;\na++;\n}\nreturn 0;\n",
"value of a: 10\nvalue of a: 11\nvalue of a: 12\nvalue of a: 13\nvalue of a: 14"));
ArrayList<String> names = new ArrayList<String>();
for (int i=0; i<ctitle.size(); i++)
{
names.add(ctitle.get(i).getTopic());
}
cAdapter = new ArrayAdapter<String>(CActivity.this, android.R.layout.simple_list_item_1, names);
ctopics.setAdapter(cAdapter);
ctopics.setOnItemClickListener(new OnItemClickListener()
{
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
{
Intent intent = new Intent(CActivity.this, Cdisplay.class);
intent.putExtra("info", ctitle.get(position));
startActivityForResult(intent, 0);
}
});
Herhangi yardım içindir Pozisyon 0 gidecek, teşekkür ederim!
Düzenleme:
genel sınıf Ctitle `Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
private String topic,code,result;
public Ctitle(String topic,String code,String result)
{
super();
this.topic=topic;
this.code=code;
this.result=result;
}
public String getTopic() {
return topic;
}
public void setTopic(String topic) {
this.topic = topic;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getResult() {
return result;
}
public void setResult(String result) {
this.result = result;
}
}
deneyin' cAdapter.getItem (konum) 'yerine ctitle.get' arasında (pozisyonu) uygular. – Titus
Im "" get "(int) yöntemi, ArrayList türü için tanımsızdır" –
James
"ArrayList" üzerinde bir "ArrayAdapter" yöntemini çağırın. Örneğin: "cAdapter.getItem (position)" – Titus