该应用程序可以正常工作到 // * ** * ** * ** * ** * ****在 ListViewActivity.java 中。在这一点之后,我希望能够单击一个项目并修改该项目。我尝试了很多例子都无济于事。我的第一个目标是能够为点击的项目敬酒。
package bipsnm.android;
import java.util.List;
import android.app.Activity;
import android.app.ListActivity;
import android.database.Cursor;
import android.database.sqlite.SQLiteException;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
public class ListViewActivity extends Activity{
public void onCreate(Bundle savedInstanceState, String[] outputData, String[]
ListView1){
super.onCreate(savedInstanceState);
Toast.makeText(this, "list/textview", Toast.LENGTH_LONG).show();
final String KEY_ROWID = "_id";
final String KEY_ITEMTYPE = "itemType";
final String KEY_QUANTITY = "quantity";
setContentView(R.layout.sqlview);
// TextView content = (TextView) findViewById(R.id.outputData);
ListView content = (ListView) findViewById(R.id.listView1);
DatabaseControl control = new DatabaseControl(this);
String result = "ItemType\t Quantity \n";
try {
control.open();
result = result + "" + control.fetchItemIdByQty();
control.close();
}catch (SQLiteException e) {
e.printStackTrace();
}
content.setFilterText(result);
//***************************************************************************
setListAdapter(new ArrayAdapter<String>(this, R.layout.sqlview,ListView1));
ListView lv = getListView();
lv.setTextFilterEnabled(true);
lv.setOnItemClickListener(new OnItemClickListener(){
public void onItemClick(AdapterView<?> parent,View view,int position,long id){
Toast.makeText(getApplicationContext(),((TextView)view).getText(),Toast.LENGTH_LONG).show();
}
});
}
private ListView getListView() {
// TODO Auto-generated method stub
return getListView();
}
private void setListAdapter(ArrayAdapter<String> arrayAdapter) {
// TODO Auto-generated method stub
}
};