2012-04-01 2 views
0

몇 가지 SMS 응용 프로그램을 개발했으며이 문제를 해결하는 방법을 알 수 없습니다 ... 하나의 레이아웃에서 두 개의 textview를 사용하여 숫자와 날짜를 표시하고 있습니다. 그 sms ... 잘 작동합니다 ...다른 클래스의 데이터로 클래스의 텍스트 뷰 채우기

하지만 이제 나는 onListItemClick을 구현하고 있는데 목록 항목을 클릭하면 데이터베이스의 전체 메시지가 새로운보기로로드되어야합니다. 나는 그것을 성취한다. ...

protected void onListItemClick(ListView l, View v, int position, long id) { 
     // TODO Auto-generated method stub 
     super.onListItemClick(l, v, position, id); 


     dba.open(); 

     Cursor c=dba.executeQuery("select rowid _id,* from messages where rowid="+position+";"); 
     Log.v(tag, "value count"+ c.getCount()); 
     if(c.getCount()>0) 
     { 
      Log.v(tag, "value count"+c.getCount()); 
      c.moveToPosition(position); 
       Intent intent = new Intent(); 

       String mesage = c.getString(c.getColumnIndex("msg")); 

       Log.v("Value passed to class", mesage); 
       intent.putExtra(name, mesage); 

      intent.setClass(this, NewInterface.class); 
      startActivity(intent); 


     } 

    } 

그리고 여기에 데이터를 전달하는 다른 클래스의 코드가있다.

protected void onCreate(Bundle savedInstanceState) { 
     // TODO Auto-generated method stub 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.messages); 
     tv4 = (TextView) findViewById(R.id.tvMessages); 
     Bundle bundle=getIntent().getExtras(); 
     if(bundle!=null) 
     { 
      Log.v("Value got from class", bundle.getString("name")); 
      tv4.setText(bundle.getString("name")); 
     } 

목록보기가 전화 번호를 포함하는 데이터베이스에서이 방법으로 채워집니다 ....

개인 무효 openAndQueryDatabase() {목록 항목의 클릭에

newDB=new DBAdapter(this); 

    try { 

     newDB.open(); 
     Cursor c = newDB.executeQuery("select distinct nm,rowid _id from messages"); 

     if (c != null) { 

      if (c.moveToFirst()) 
       Log.v(tag, "Stage 1");{ 
       do { 

        String firstName = c.getString(c.getColumnIndex("nm")); 
        Log.v(tag, firstName); 
       // String date = c.getString(c.getColumnIndex("dt")); 

        results.add(firstName); 


       }while (c.moveToNext()); 
       Log.v(tag, "Stage 1"); 
      } 
     }   
+0

당신이 직면 한 문제는 무엇입니까 – Ishu

+0

나는 사용자가 특정 listitem을 클릭하면 특정 listviewitem에 표시된 전화 번호를 얻은 다음 그 번호에 대한 데이터베이스 쿼리를 수행하고 메시지를 가져 와서 해당 데이터를 전달하기를 원합니다. 다른 레이아웃에 다른 클래스를 표시하기 위해 다른 클래스에 ... – kashifmehmood

+0

당신은 getview()를 추가 할 수 있습니까? 정확히 listview 항목에 포함 된 것은 데이터 – Ishu

답변

1

당신이 여는 db가 클릭 된 위치를 기반으로 데이터를 가져옵니다. 첫 번째 Activity 전체를 읽는 대신 Intent를 사용하여 int 위치를 다음 Activity로 전달한 다음 데이터베이스 쿼리를 작성하십시오. 더 쉽고 이해하기 쉬울 것입니다. 당신은 여전히 ​​wholde 데이터를 전달 아래와 같은 코드를 사용하려면 (당신의 if(c.getCount>0) 블록 교체) :

ArrayList<String> arrayList ; 

      Cursor c=null; 
      if(c.moveToFirst()){ 
       int x= c.getCount(); 
       int y =c.getColumnIndex("msg"); 
      arrayList = new ArrayList<String>(x); 
       for(int a=0;a<x;a++){ 
c.moveToPosition(a);      
arrayList.add(c.getString(y)); 

       } 
        Intent intent = new Intent(this,NewInterface.class); 
       intent.putStringArrayListExtra("msgs",arrayList); 
      startActivity(intent); 
      } 

은 ListView에 당신의 클릭 한 행의 textViews 중 하나에서 번호를 얻으려면 :

TextView tv1=(TextView)v.findViewbyId(R.id.number)//Replace this with id of tv displaying numbers 
String number = tv1.getText().toString(); 

이 줄을 onListItemClick에 추가 한 다음이 번호를 쿼리에 사용하십시오.

+0

을 의미하지만 문제는 ... 위치 변수가 반환 될 때입니다. int ... 목록에 표시되는 전화 번호가 필요한 동안 ... 그리고 그 전화 번호에 따라 데이터베이스 쿼리를 수행하십시오 .... 나를 얻으려는 희망 .. – kashifmehmood

+0

listview는 숫자가 아닌 textview를 표시합니다 .... 그 textview thats 클릭 한되는 listviewitem thats 클릭 한 및 해당 listviewclick 기준으로 데이터베이스의 데이터로 textview를 채우고 싶습니다 ... – kashifmehmood

+0

위의 두 줄을 추가 했습니까? – Akhil

관련 문제