Android listview和tabview在同一活动中
我正在努力让listview和tabactivity一起工作。有没有人能告诉我如何在1个activity.xml文件中同时使用这两个类(我想应该是这样的) 布局如下所示Android listview和tabview在同一活动中,android,listview,tabview,Android,Listview,Tabview,我正在努力让listview和tabactivity一起工作。有没有人能告诉我如何在1个activity.xml文件中同时使用这两个类(我想应该是这样的) 布局如下所示 ________________________________________ | _____ _____ _____ _____ | | | btn | | btn | | btn | | btn | | | |_____| |_____| |_____| |_____| | |
________________________________________
| _____ _____ _____ _____ |
| | btn | | btn | | btn | | btn | |
| |_____| |_____| |_____| |_____| |
|______________________________________|
| | |
| | |
| | |
| list | tab contents |
| | |
| view | |
| | |
| contents | |
| | |
| here | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
|______________|_______________________|
| ____ ____ | | | |
| |NXT ||PRV | | TAB1 | TAB2 | TAB3 |
| |____||____| | | | |
|______________|______|_______|________|
布局代码:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:background="@drawable/bg"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="125dp"
android:layout_marginTop="100dp" >
<TabHost
android:id="@android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_marginTop="310dp" >
</TabWidget>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentRight="true" >
</FrameLayout>
</RelativeLayout>
</TabHost>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_gravity="left"
android:layout_marginRight="203dp"
android:layout_marginTop="100dp"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="50dp" >
<TextView
android:id="@android:id/textview_peoples"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</TextView>
</LinearLayout>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_weight="1"
android:maxWidth="70dp"
android:minHeight="60dp"
android:minWidth="55dp"
android:text="Prev"
android:textSize="13sp" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_toRightOf="@+id/button1"
android:layout_weight="1"
android:maxWidth="70dp"
android:minHeight="60dp"
android:minWidth="55dp"
android:text="Next"
android:textSize="13sp" />
</RelativeLayout>
<Button
android:id="@+id/btn_category_back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="Back" />
<Button
android:id="@+id/btn_category_search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/btn_category_back"
android:text="Search" />
<Button
android:id="@+id/btn_category_ts"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/btn_category_search"
android:text="TS" />
<Button
android:id="@+id/button6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/btn_category_ts"
android:text="Button" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentEnd="true"
android:layout_marginBottom="360dp"
android:layout_marginTop="50dp"
android:orientation="vertical"
android:textAlignment="center"
android:layout_gravity="center" >
<TextView
android:id="@+id/textView_ppp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_marginTop="9dp"
android:background="@color/greyish"
android:text="PPP"
android:textAlignment="center"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
</RelativeLayout>
我用于listview的类代码:
import android.os.Bundle;
import android.app.ListActivity;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
public class SavedSearches extends ListActivity
{
// defining array to store string resources
String[] various_peoples;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
// storing string resources into Array
various_peoples = getResources().getStringArray(R.array.various_people);
// Binding resources Array to ListAdapter
this.setListAdapter(new ArrayAdapter<String>
(this,R.layout.category_peoples, R.id.textview_peoples,various_peoples));
}
}
最终,我需要listview和tabview一起工作,如果我选择了与listview不同的内容,它应该加载一组新的选项卡内容,但我将自己处理/尝试
提前感谢,我认为这是它应该如何工作的)-这不是它应该如何工作的。您需要一个具有您发布的布局的活动,在该活动中,您将为
列表视图和选项卡设置适配器。如果要在列表和选项卡之间进行通信,请使用片段而不是活动作为选项卡(另外,TabActivity
也有一段时间不推荐使用)。是否查看本教程?是的,看了那个教程,我看不出它对我有用。我需要一个listview和选项卡,而本教程在tabview中实现listview。“我的选项卡”中将包含静态内容,listview中的每个列表项都应将选项卡更改为与列表主题相关的新内容。我试着将上述教程的内容分开,看看它是否对我有帮助,但是给了我太多的错误。好吧,所以我设法让它工作了……然后tabactivity改变了
import android.os.Bundle;
import android.app.ListActivity;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
public class SavedSearches extends ListActivity
{
// defining array to store string resources
String[] various_peoples;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
// storing string resources into Array
various_peoples = getResources().getStringArray(R.array.various_people);
// Binding resources Array to ListAdapter
this.setListAdapter(new ArrayAdapter<String>
(this,R.layout.category_peoples, R.id.textview_peoples,various_peoples));
}
}
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class subCategories extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.btn_subcategories);
Button btn_SubCategories_PPP = (Button) findViewById(R.id.btn_SubCategories_PPP);
btn_SubCategories_PPP.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(v.getContext(), subCategories_peoples.class);
startActivityForResult(intent, 1);
}
})
;
}
}