2012-08-28 92 views
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> 
+0

你可能应该调用'finish()'而不是'onPause()'(它只能被系统调用) – fiddler

+0

尝试在你的xml中添加LinearLayout作为基础。 – Niko

+0

我什么都没做完。它是线性的我不知道它为什么没有出现 – MayTheSchwartzBeWithYou

回答

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()。

+0

我刚刚看到它。我是个假人。我现在已经过了1个小时。 – MayTheSchwartzBeWithYou

+1

它一直发生..即使对我来说一次.. –

2

onStart()替换为onCreate()并且从setOnItemClickListener()删除onPause(); 。