我是新的@andorid開發。請幫我解決這個問題。在構造函數上創建Android本地公共類textview
這裏是我的問題:
創建listview.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:gravity="left|center"
android:layout_width="wrap_content"
android:paddingBottom="5dp"
android:paddingTop="5dp"
android:paddingLeft="5dp">
<TextView android:id="@+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:textColor="#FFFF00"
android:textIsSelectable="true">
</TextView>
<TextView android:id="@+id/TextView02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:textColor="#0099CC"
android:textIsSelectable="true">
</TextView>
和地方類聲明:
public class listview_row{
TextView Text1;
TextView Text2;
public listview_row(){
Text1 = (TextView) findViewById(R.id.TextView01);
Text2 = (TextView) findViewById(R.id.TextView02);
}
}
,當我從這個類來創建對象:
listview_row obListview = new listview_row();
obListview.Text1.setText(bundle.getString("first_name"));
obListview.Text2.setText(bundle.getString("last_name"));
obListview.Text1 allways equal null and nullobjectexecption is raising。我怎樣才能解決這個問題。 我以爲我可以在構造函數上創建textview,但我想我錯了。
PS:我想創建帶有兩個textview的Listview,我使用了android.R.layout.simple_list_item_1,並且我可以設法在兩個acticity之間傳遞數據,沒有任何問題。現在我嘗試顯示first_name | last_name @first screen listview。
對於這裏的詳細信息是我的onActivityResult:
public void onActivityResult(int requestCode, int resultCode, Intent intent){
if (resultCode == RESULT_OK){
Bundle extras = intent.getExtras();
if (extras != null){
switch (requestCode){
case Activity_New:
add_new_row(extras);
break;
case Activity_Edit:
edit_row(extras);
break;
}}
}
}
,這是add_new_row: 公共無效add_new_row(束束){// Başlıkbilgilerinikayıtediyoruz INT卅一= HeaderArray.size(); listview_row obListview = new listview_row(); obListview.Text1.setText(bundle.getString(「first_name」)); obListview.Text2.setText(bundle.getString(「last_name」));
HeaderArray.add(sayi, obListview);
HeaderAdapter.notifyDataSetChanged();
// Kalem bilgilerini kayıt ediyoruz
mtable_row obMember = new mtable_row();
obMember.index = sayi;
obMember.first_name = bundle.getString("first_name");
obMember.last_name = bundle.getString("last_name");
obMember.birth_date = bundle.getString("birth_date");
itemArray.add(sayi, obMember);
}
我使用詳細信息陣列:
private ArrayList<mtable_row> itemArray;
public class mtable_row{
int index;
String first_name;
String last_name;
String birth_date;
}
我的主要目標是工作有兩個陣列: 第一個是標題和第二個是項目。 標題有兩個字段first_name和second_name
我喜歡在我的主屏幕上顯示此數組。
這是什麼'內listview_row'指'Text1'和'Text2'?您顯然不會設置它們...... – t0mm13b