2011-04-10 8 views
0

다음 활동으로 이동하여 의도 한 데이터를 전달할 때 DB에 마지막 항목이 표시되고 클릭 된 항목 정보가 표시되지 않는 문제가 있습니다.의도 데이터가 올바르게 표시되지 않습니다.

된 .java

public class TimsFavs extends ListActivity implements OnItemClickListener { 

/** Called when the activity is first created. */ 
ArrayList<String> results = new ArrayList<String>(); 

// Database results 
String col0,col1,col2,col3,col4,col5,col6,col7; 

@Override 
public void onCreate(Bundle savedInstanceState) 
{ 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.timsfavs); 
    DBAdapter db = new DBAdapter(this); 

    //---get all Locations--- 
    db.open(); 

    Cursor c = db.getAllLocation(); 

    if (c.moveToFirst()) 
    { 
     do { 

      col0 = c.getString(c.getColumnIndex(DBAdapter.KEY_ROWID)); 
      col1 = c.getString(1); 
      col2 = c.getString(2); 
      col3 = c.getString(3); 
      col4 = c.getString(4); 
      col5 = c.getString(5); 
      col6 = c.getString(6); 
      col7 = c.getString(7); 

      results.add(col0); 

     } while (c.moveToNext()); 
    } 
    db.close(); 

    setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,results)); 
    ListView lv; 
    lv = getListView(); 
    lv.setTextFilterEnabled(true); 
    lv.setBackgroundColor(Color.rgb(83, 05, 14)); 
    lv.setOnItemClickListener((OnItemClickListener) this); 

} 

public void onItemClick(AdapterView<?> TimsFavs, View view, int position, long id) { 

    Intent i = new Intent(getApplicationContext(), TimsFavsMore.class); 

    i.putExtra("ct_id_pass", col0); 
    i.putExtra("ct_storeid_pass", col1); 
    i.putExtra("ct_address_pass", col2); 
    i.putExtra("ct_city_pass", col3); 
    i.putExtra("ct_province_pass", col4); 
    i.putExtra("ct_country_pass", col5); 
    i.putExtra("ct_pcode_pass", col6); 
    i.putExtra("ct_phnum_pass", col7); 

    startActivity(i); 
    finish(); 

} 

}

내 다른 활동

이다는`공용 클래스 TimsFavsMore는 활동 { DBAdapter의 dB = 새로운 DBAdapter (이) 확장;

String rowId; 

@Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.timsfavsmore); 

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

     final String rowId = b.getString("ct_id_pass"); 
     final String phnum = b.getString("ct_phnum_pass"); 
     final String storeid = b.getString("ct_storeid_pass"); 
     final String address = b.getString("ct_address_pass"); 
     final String city = b.getString("ct_city_pass"); 
     final String province = b.getString("ct_province_pass"); 
     final String country = b.getString("ct_country_pass"); 
     final String pcode = b.getString("ct_pcode_pass"); 

     TextView title = (TextView) findViewById(R.id.textview); 
     title.setText(Html.fromHtml("<br>Row ID: " + rowId + "<br><b><u>Location Address:</u></b><br><br>Store #" + storeid + "<br><br>" + address + "<br>" + city + ", " + province + "<br>" + country +"<br>" + pcode +"<br><br><b><u>Contact Info:</b></u><br><br>" + phnum +"<br>")); 

// open to Nav 

final Button button1 = (Button) findViewById(R.id.gohere); 
button1.setOnClickListener(new View.OnClickListener() { 
    public void onClick(View v) { 

     String uri = "google.navigation:q=Tim%20Hortons,%20" + address + ",%20" + city + ",%20" + province + ",%20" + pcode + ""; 
     Intent i2 = new Intent(Intent.ACTION_VIEW, Uri.parse(uri)); 
     startActivity(i2); 

    } 
}); 

// open to maps 

final Button button2 = (Button) findViewById(R.id.showmap); 
button2.setOnClickListener(new View.OnClickListener() { 
    public void onClick(View v) { 

     String uri2 = "geo:0,0?q=Tim%20Hortons,%20" + address + ",%20" + city + ",%20" + province + ",%20" + pcode + ""; 
     Intent i3 = new Intent(Intent.ACTION_VIEW, Uri.parse(uri2)); 
     startActivity(i3); 

    } 
}); 

// Add to My Timmies List 

final Button button3 = (Button) findViewById(R.id.removefav); 
button3.setOnClickListener(new View.OnClickListener() { 
    public void onClick(View v) { 

     //---add 2 SQLite--- 

     db.open(); 

     if (db.deleteLocation(rowId)) 
      Toast.makeText(getApplicationContext(), " Delete successful.", 
       Toast.LENGTH_LONG).show(); 
     else 
      Toast.makeText(getApplicationContext(), "Delete failed.", 
       Toast.LENGTH_LONG).show();    
     db.close(); 

     Intent i = new Intent(getApplicationContext(), MyTimmies.class); 
     startActivity(i); 
     finish(); 

    } 
}); 


final Button button4 = (Button) findViewById(R.id.favsdone); 
button4.setOnClickListener(new View.OnClickListener() { 
    public void onClick(View v) { 

    Intent i4 = new Intent(getApplicationContext(), MyTimmies.class); 
     startActivity(i4); 
     finish(); 

    } 
}); 
} 

}`

어떤 아이디어가?

답변

0

커서를 반복하여 문자열에 값을 할당하고 있습니다. 반복을 완료하면 문자열에 지정한 마지막 값만 포함 된 다음 전달됩니다.

전체 문자열 배열을 만드는 대신 목록을 SimpleCursorAdapter에 바인딩해야합니다. 그런 다음 onClickListener에서 데이터베이스의 데이터 행을 식별하는 키를 전달하면됩니다.

+0

네, 지금 당장 나는 코딩 방향을 알아 내야 만합니다. – PsychoDogg

+0

메모장 샘플을 보면 커서에 바인딩되는 간단한 목록보기가있어서 좋은 시작 지점을 제공해야합니다. http://www.google.com/url?sa=t&source=web&cd=1&sqi=2&ved=0CBsQFjAA&url=http%3A%2F%2Fdeveloper.android.com%2Fresources%2Ftutorials%2Fnotepad%2F&rct=j&q=android%20notepad% 20example & ei = wEeiTfOgB5T2gAfz8tnaBQ & usg = AFQjCNGqDN3kFwMcsPBsIQbCFK69WM1cQg & cad = rja – jkhouw1

+0

나는 메모장을보고 쳐다보고 머리 나 꼬리를 만들지 않습니다. – PsychoDogg

관련 문제