0

我有一个调用 onItemClick 并启动另一个活动的活动。这个活动有一个静态布局(用于测试目的),但我看到的只有黑色(我什至将文本颜色设置为白色以检查它)。

我的听众

 list.setOnItemClickListener(new OnItemClickListener() {

        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,long arg3) {
            //create new intent
            Intent item = new Intent(getApplicationContext(), Item.class);
            // Close all views before launching logged
            //item.putExtra("name", ((TextView)arg1).getText());
            //item.putExtra("uid", user_id);
            item.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            startActivity(item);
            // Close Login Screen
            onPause();
        }
      });

我的活动在这里(没什么可做的,只是启动布局)

public class Item extends Activity{
protected SQLiteDatabase myDB=null;
protected String name;
protected int uid;
TextView yeart,year,itemname,comment,commentt,value,valuet,curr,currt;


protected void onStart(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    setContentView(R.layout.herp);
    /*name=getIntent().getStringExtra("name");
    uid=Integer.parseInt(getIntent().getStringExtra("uid"));

    itemname=(TextView) findViewById(R.id.itemName);//itemname.setText(name);
    year=(TextView) findViewById(R.id.itemYear);
    yeart=(TextView) findViewById(R.id.year);
    comment=(TextView) findViewById(R.id.itemComments);
    commentt=(TextView) findViewById(R.id.comments);
    curr=(TextView) findViewById(R.id.itemcurrent);
    currt=(TextView) findViewById(R.id.current);
    value=(TextView) findViewById(R.id.itemValue);
    valuet=(TextView) findViewById(R.id.value);*/



    Database openHelper = new Database(this);
    myDB = openHelper.getReadableDatabase(); 
    myDB=SQLiteDatabase.openDatabase("data/data/com.example.login2/databases/aeglea", null, SQLiteDatabase.OPEN_READONLY);


}}

最后是我的 XML 布局

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

<TextView
        android:id="@+id/itemName"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="asdasd"
        android:gravity="center"
        android:layout_marginBottom="10px"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textColor="#fff" />

    <TextView
        android:id="@+id/current"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Current"
        android:textSize="20dp"
        android:textStyle="bold" />

    <TextView
        android:id="@+id/itemcurrent"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="asdasd" />

    <TextView
        android:id="@+id/year"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Year"
        android:textSize="20dp"
        android:textStyle="bold" />

    <TextView
        android:id="@+id/itemYear"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="asdasd" />

    <TextView
        android:id="@+id/value"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Value"
        android:textSize="20dp"
        android:textStyle="bold" />

    <TextView
        android:id="@+id/itemValue"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="TextView" />

    <TextView
        android:id="@+id/comments"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Comments"
        android:textSize="20dp"
        android:textStyle="bold" />

    <TextView
        android:id="@+id/itemComments"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="TextView" />
</LinearLayout>
4

2 回答 2

5

你能试试这个吗

public void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    setContentView(R.layout.herp);
    /*name=getIntent().getStringExtra("name");
    uid=Integer.parseInt(getIntent().getStringExtra("uid"));

    itemname=(TextView) findViewById(R.id.itemName);//itemname.setText(name);
    year=(TextView) findViewById(R.id.itemYear);
    yeart=(TextView) findViewById(R.id.year);
    comment=(TextView) findViewById(R.id.itemComments);
    commentt=(TextView) findViewById(R.id.comments);
    curr=(TextView) findViewById(R.id.itemcurrent);
    currt=(TextView) findViewById(R.id.current);
    value=(TextView) findViewById(R.id.itemValue);
    valuet=(TextView) findViewById(R.id.value);*/



    Database openHelper = new Database(this);
    myDB = openHelper.getReadableDatabase(); 
    myDB=SQLiteDatabase.openDatabase("data/data/com.example.login2/databases/aeglea", null, SQLiteDatabase.OPEN_READONLY);


}}

我认为你应该使用 onCreate() 而不是 onStart()。

于 2012-08-28T09:33:00.187 回答
2

替换onStart()为并从中onCreate()删除;.onPause()setOnItemClickListener()

于 2012-08-28T09:34:36.790 回答