2012-12-15 1 views
1

데이터베이스의 두 열을 쿼리하고 간단한 커서 어댑터를 사용하여 쿼리를 표시하는 주요 활동에 커서가 있습니다. 내가 원하는 무엇simplecursoradapter에서 하나의 열만 선택하고 다른 활동을 전달하는 방법은 무엇입니까?

private Cursor doQuery() { 
return(db.getReadableDatabase().rawQuery("SELECT RestaurantID AS _id, RestaurantName, StoreNo " 
+ "FROM RestaurantList ORDER BY RestaurantName", null)); 

} 

public void onPostExecute() { 
SimpleCursorAdapter adapter; 

if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.HONEYCOMB) { 
adapter=new SimpleCursorAdapter(this, R.layout.activity_all_restaurants, 
     doQuery(), new String[] { 
    RestaurantDB.colRestaurantName, 
    RestaurantDB.colRestaurantStore }, 
    new int[] { R.id.title, R.id.value }, 
    0); 
} 
else { 
adapter=new SimpleCursorAdapter(this, R.layout.activity_all_restaurants, 
     doQuery(), new String[] { 
    RestaurantDB.colRestaurantName, 
    RestaurantDB.colRestaurantStore }, 
    new int[] { R.id.title, R.id.value }); 
} 

setListAdapter(adapter); 

} 

는 사용자가 특정 항목을 클릭 할 때, 다른 활동이 내가 많은 열에 저장된 데이터를 표시해야 즉, 사용자에게 더 많은 정보를 제공하는 팝업 것입니다 같은 항목도. 내 질문은 어떻게 할 수 있느냐입니다. onListItemClick을 사용해야한다고 생각했지만 기본 활동에서 선택한 항목을 새 활동에 연결하는 방법을 모르겠습니다.

또한 주 활동에서 colRestaurantName과 colRestaurantStore를 각각 표시하는 두 개의 textview가 목록에 있습니다. onListItemClick을 사용할 때 colRestaurantName을 검색하는 방법은 무엇입니까?

는 나는이 위치를 검색하기 위해 다음을 수행 할 수 있습니다,하지만 난 새로운 활동에 사용할 수있는 방법을 모른다 :

@Override 
public void onListItemClick(ListView parent, View v, int position, 
    long id){ 
Cursor c = ((SimpleCursorAdapter)parent.getAdapter()).getCursor(); 
selection = String.valueOf(c.getPosition()); 
Intent i = new Intent(AllRestaurants.this, RestaurantsInfo.class); 
i.putExtra("restaurantSelection", selection); 
startActivity(i);  
} 

감사합니다.

답변

0

리스트 뷰에 대한 onListItemClick를 구현하고 텍스트 뷰의 텍스트를 얻을으로 다음 활동으로 보내 :

@Override 
protected void onListItemClick(ListView l, View v, int position, long id) { 
    super.onListItemClick(l, v, position, id); 
     TextView tv = (TextView)v.findViewById(R.id.title); 
     String strcolRestaurantName=tv.getText().toString(); 

     Intent intent =new Intent(CurrentActivity.this,NextActivity.class); 
     Bundle bundle = new Bundle(); 
     bundle.putString("RestaurantName",strcolRestaurantName); 
     intent.putExtras(bundle); 
     startActivity(intent); 
}} 

및 NextActivity에에서 onCreate 같이 의도를 얻을 :

Intent i = getIntent(); 
Bundle extras = i.getExtras(); 

String strRestaurantName = extras.getString("RestaurantName"); 
+0

우수함! 감사. 나는 나머지를 알아낼 것이다. – androidnerd

+0

@ JYLim : 대부분 환영 코드 친애하는 친구 !!! :) –