0
我在我的應用程序中有一個顯示數據庫元素的listview。列表視圖的每個元素都顯示一些來自我的數據庫元素的內容以及一個按鈕。通過它的ID獲取字符串的長度(R.id.)
稍後,我將使該按鈕打開手機的撥號菜單,並單擊時撥打一個號碼。我現在想要的只是當我的數據庫與listview關聯的元素的長度等於7時,才顯示此按鈕。我的問題是獲取此字符串的長度,因爲它使用對象的id從我的數據庫中調用。
這裏是我的代碼,我想檢查長度的元素是「電話」與R.id.telephone,它是從數據庫中調用,然後發送到另一個活動:
private void displayListView() {
// getExtra
Bundle bundle = getIntent().getExtras();
String title = bundle.getString("title", "Choose here :");
String inInterval = bundle.getString("inInterval");
Log.d(TAG, "inInterval = " + inInterval);
poititle.setText(title);
// put the results of the method in a cursor
Cursor c = dbHelper.findPoiInTable(inInterval);
String[] columns = new String[] { DatabaseAdapter.COL_NAME,
DatabaseAdapter.COL_STREET, DatabaseAdapter.COL_WEBSITE,
DatabaseAdapter.COL_TELEPHONE, DatabaseAdapter.COL_REMARKS,
DatabaseAdapter.COL_PRICE };
int[] to = new int[] { R.id.name, R.id.street, R.id.website,
R.id.telephone, R.id.remarks, R.id.price };
cursorAdapter = new SimpleCursorAdapter(this, R.layout.poi_info, c,
columns, to, 0);
ListView listView = (ListView) findViewById(R.id.poilistview);
// Assign adapter to ListView
listView.setAdapter(cursorAdapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
// Comportement des éléments de la listview
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
Intent i = new Intent(getApplicationContext(),
POIActivity.class);
String name = ((TextView) view.findViewById(R.id.name))
.getText().toString();
String website = ((TextView) view.findViewById(R.id.website))
.getText().toString();
String telephone = ((TextView) view
.findViewById(R.id.telephone)).getText().toString();
String remarks = ((TextView) view.findViewById(R.id.remarks))
.getText().toString();
String price = ((TextView) view.findViewById(R.id.price))
.getText().toString();
// i.putExtra(ID_EXTRA, name) ;
i.putExtra(ID_NAME, name);
i.putExtra(ID_WEBSITE, website);
i.putExtra(ID_TELEPHONE, telephone);
i.putExtra(ID_REMARKS, remarks);
i.putExtra(ID_PRICE, price);
startActivity(i);
}
}); }
這裏是我的嘗試:我創建了一個方法callbuttonManagement()中,我從我的diplsayListView()方法調用它的代碼是上述相同的活動,而我定義是這樣的:
public void callbuttonManagement() {
int countTelephone = ID_TELEPHONE.length();
if (countTelephone == 7)
{
callButton.setVisibility(View.VISIBLE);
}
else
{
callButton.setVisibility(View.GONE);
}
}
它崩潰我的應用程序的logcat表示空投影。有什麼建議麼 ?謝謝 !
那裏ID_TELEPHONE從哪裏來? –
是活動POIActivity中的callbuttonManagement? –
ID_TELEPHONE是在組織列表元素的佈局中定義的,如下所示: 我這樣做是因爲我需要在某個地方定義它,否則它將無法工作。 –
Phalanx