0

在框架布局/选项卡布局中实现列表视图时,我得到了错误的回报。对于我的一生,我似乎无法弄清楚为什么在实现列表视图时我的应用程序会得到错误的回报。该代码适用于外部项目,但我似乎无法将其集成到这个项目中。我将列出项目中使用的主要活动组以及字符串要出现的页面的 xml 文件。对不起,它有很多代码,但这在过去几天里一直让我发疯,因为它应该相对简单。

xml 布局文件保存在 main.xml 中的 framelayout 编码中(未显示),所以在引用时我的 ID 是否错误?解决这个问题的任何帮助都会令人惊叹,因为我知道这是一个非常简单的解决方案,我只是想念它。多谢你们。

如果我没有很好地解释它,错误的图片在下面查看页面http://i41.tinypic.com/do04ee.png

它们没有日志错误。

主要活动 (请注意,我已删除代码以使其更加相关和清晰,并显示活动之间的链接)

package workout.fitty;

import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.widget.TabHost;

public class WorkoutFittyActivity extends TabActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    Resources res = getResources(); // Resource object to get Drawables
    TabHost tabHost = getTabHost();  // The activity TabHost
    TabHost.TabSpec spec;  // Resusable TabSpec for each tab
    Intent intent;  // Reusable Intent for each tab

 // More

    **intent = new Intent().setClass(this, MoreActivity.class);
    spec = tabHost.newTabSpec("songs").setIndicator("More",
                      res.getDrawable(R.drawable.tab_more))
                  .setContent(intent);
    tabHost.addTab(spec);**

    tabHost.setCurrentTab(1);
}
}

更多活动

package workout.fitty;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

public class MoreActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.more_layout);
    Intent Intent = new Intent(this, MyListActivity.class);
}
}

我的列表活动

package workout.fitty;

import android.app.ListActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

    public class MyListActivity extends ListActivity {
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    String[] values = new String[] { "BMI", "Body Measurements", "Logs",
            "Feedback", "How To Use", "About" };
    // Use your own layout
    **ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
            R.layout.more_layout, R.id.label, values);
    setListAdapter(adapter);**
}

@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
    String item = (String) getListAdapter().getItem(position);
    Toast.makeText(this, item + " selected", Toast.LENGTH_LONG).show();
}

}

和 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" >

<ImageView
    android:id="@+id/icon"
    android:layout_width="22px"
    android:layout_height="22px"
    android:layout_marginLeft="4px"
    android:layout_marginRight="10px"
    android:layout_marginTop="4px"
    android:src="@drawable/ic_launcher" >
</ImageView>

<TextView
    android:id="@+id/label"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@+id/label"
    android:textSize="20px" >
</TextView>

</LinearLayout>

带有容器和框架布局的主 XML 文件

    <?xml version="1.0" encoding="utf-8"?>
    <TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="5dp">

        <TabWidget
        android:id="@android:id/tabs"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />


    <FrameLayout
        android:id="@android:id/tabcontent"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:padding="5dp" />
</LinearLayout>

</TabHost>
4

1 回答 1

0

改变你的:

ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
        R.layout.more_layout, R.id.label, values);

   ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
       R.layout.more_layout, values);
于 2012-02-14T14:37:23.813 回答