我得到了这个代码:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_clicked);
String query = "SELECT ROWID _id, linie"
+ " FROM linie";
ArrayList<String> HaltestellenListe = CursorToArray(getApplicationContext(), query, new String[] {});
final ListView lvD = (ListView) findViewById(R.id.lvClicked);
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, R.layout.activity_clicked, R.id.tvClicked, HaltestellenListe);
lvD.setAdapter(arrayAdapter);
lvD.setDividerHeight(8);
lvD.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String linie = lvD.getItemAtPosition(position).toString();
}
});
}
public ArrayList<String> CursorToArray(Context ApplicationContext, String query, String[] whereClause){
ArrayList<String> ArrayList = new ArrayList<String>();
DataBaseHelper dbHelper = new DataBaseHelper(getBaseContext());
Cursor c = dbHelper.dbHelper(ApplicationContext).rawQuery(query, whereClause);
dbHelper.close();
c.moveToFirst();
while (!c.isAfterLast()){
if (c.isNull(c.getColumnIndex("linie")) == false){
ArrayList.add(c.getString(c.getColumnIndex("linie")));
}
c.moveToNext();
}
c.close();
return ArrayList;
}
使用 setonitemclicklistener 我得到点击位置的字符串。我如何将此字符串用于这样的新字符串查询:
lvD.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
setContentView(R.layout.activity_clicked);
String newQuery = "SELECT ROWID _id, linie" + "FROM linie" + "WHERE name =" + lvD.getItemAtPosition(position).toString();
ArrayList<String> ClickedList = CursorToArray(getApplicationContext(), newQuery, new String[] {});
final ListView lvD = (ListView) findViewById(R.id.lvClicked);
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, R.layout.activity_clicked, R.id.tvClicked, ClickedList);
lvD.setAdapter(arrayAdapter);
lvD.setDividerHeight(8);
}
});
我希望新文本在同一个列表视图中,我想在新查询中使用第一个查询中的字符串。我对java很陌生,所以请帮助我。