2011-12-08 30 views
0

我希望能夠從列表視圖中獲取一行,並在不同的活動中填充textViews。我希望能夠做的列表視圖項的這個的onclick ..我如何轉換此代碼,以便我可以從列表視圖中獲取行

public class CBFilter extends Activity { 

    ListView RecipeNames; 
    Cursor cursor; 
    SimpleCursorAdapter adapter; 
    CBDataBaseHelper data; 
    SQLiteDatabase data2; 
    TextView RecipeText; 

    public void onCreate(Bundle savedInstanceState) { 

     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 

     RecipeNames = (ListView) findViewById(R.id.List1); 
     RecipeNames.setTextFilterEnabled(true); 
     RecipeText = (TextView) findViewById(R.id.recipeText); 
     adapter = new SimpleCursorAdapter (this, 0, cursor, null, null); 

     data = new CBDataBaseHelper(this); 
     data.open(); 
     cursor = data.query(); 
     startManagingCursor(cursor); 

     String[] from = {CBDataBaseHelper.KEY_NAME}; 
     int[] to = { R.id.recipeText}; 


     adapter = new SimpleCursorAdapter(this, R.layout.row, cursor, from, to); 
     RecipeNames.setAdapter(adapter); 
     adapter.notifyDataSetChanged(); 



    } 

    public void CreateNew(View view){ 

     Intent myIntent = new Intent(this, CBCreate.class); 
     startActivity(myIntent); 
    } 
} 

我怎樣才能把這段代碼轉換,以實現所需的功能..感謝斯特凡

回答

0

嘗試這樣

public void onListItemClick(ListView parent, View v, int position, long id) { 
    String string = from[position]); // this depends on your Adapter ... 
    Intent i = new Intent(CheckData.this,ShowData.class); 
    i.putExtra("SELECTED", string); 
    startActivity(i); 

我是從這個鏈接,它將使用全給你: Use of SQLite

+0

嗯這是否暗示,然後我將不得不創建一個又一個CL屁股,擴大列表活動? – aspiringCoder

相關問題