0

该应用程序可以正常工作到 // * ** * ** * ** * ** * ****在 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
}
};
4

1 回答 1

1
// binding array to ListAdapter
setListAdapter(new ArrayAdapter<String>
           (this,android.R.layout.simple_expandable_list_item_1,result));
    selection = (TextView)findViewById(R.id.selection);


// listening to single list item on click
protected void onListItemClick(ListView l,View v, int position, long id){
    super.onListItemClick(l, v, position, id);
// selected item
String product = result[position];
Intent ii = new Intent(getApplicationContext(),Desire.class);
// sending data to new activity
ii.putExtra("product", product);
startActivity(ii);
};
于 2012-12-09T21:17:37.777 回答