onclick sqlite项目

时间:2012-06-16 21:49:30

标签: android android-listview

该应用可以正常工作// * ** * ** * ** * ** * **** 。在此之后,我希望能够单击某个项目并修改该项目。我试过很多例子无济于事。我的第一个目标是能够为点击的项目干杯。

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
}
};

1 个答案:

答案 0 :(得分: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);
};