I am having a silly problem with a OnItemCliskListener for my ListView. It works well when the XML is very simple but after I improve its complexity, the OnItemCliskListener stop working
In other words, I have a ListView with just a TextView. But if I turn my ListView into a more complex list with other TextView, an Icon a CheckBox, the ClickListener stop working.
If I run exactly the same code changing just the XML, the OnItemCliskListener stops working. I would be rather grateful if you could help me
WORKING LIST VIEW:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:orientation="vertical"
android:layout_height="fill_parent">
<TextView android:id="#+id/title"
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:layout_toLeftOf="#+id/appCheck"
android:layout_toRightOf="#+id/appIcon"
android:textAppearance="?android:attr/textAppearanceLarge">
</TextView>
</RelativeLayout>
NOT WORKING LISTVIEW:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:orientation="vertical"
android:layout_height="fill_parent">
<ImageView android:src="#drawable/icon" android:id="#+id/appIcon"
android:layout_width="30px" android:layout_height="40px"></ImageView>
<CheckBox android:id="#+id/appCheck"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_alignParentRight="true"></CheckBox>
<TextView android:id="#+id/title"
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:layout_toLeftOf="#+id/appCheck"
android:layout_toRightOf="#+id/appIcon"
android:textAppearance="?android:attr/textAppearanceLarge">
</TextView>
<TextView android:id="#+id/subtitle"
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:layout_toLeftOf="#+id/appCheck"
android:layout_toRightOf="#+id/appIcon" android:layout_below="#+id/title"
android:textAppearance="?android:attr/textAppearanceSmall">
</TextView>
</RelativeLayout>
MY JAVA ACTIVITY:
public class MyTabsActivity extends TabActivity implements OnTabChangeListener {
private static final String LIST3_TAB_TAG = "List3";
private RelativeLayout layoutTab3;
private MyArrayAdapter adapterListViewTab3;
private TabHost tabHost;
...
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tabHost = getTabHost();
tabHost.setOnTabChangedListener(this);
...
...
// ----------------- BUILD TAB3
// That is my Tab of Running App
layoutTab3 = (RelativeLayout) findViewById(R.id.running_app_relative_layout);
// Fill my ListView of Running App
ListView runningAppList = (ListView) findViewById(R.id.running_app_listview);
List<String> list3Strings = new ArrayList<String>();
list3Strings.add("Item 1");
list3Strings.add("Item 2");
list3Strings.add("Item 3");
list3Strings.add("Item
adapterListViewTab3 = new MyArrayAdapter(this, android.R.layout.simple_list_item_1, list3Strings);
runningAppList.setAdapter(adapterListViewTab3);
// ????????????????????????????????????????????????????????????????????????????????????????????
// >>>>>>>>>>>> THIS OnItemClickAdapter DOESN'T WORK !!!!! WHY ????????
runningAppList.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
Toast.makeText(MyTabsActivity.this, "EUREKA", Toast.LENGTH_SHORT).show();
}
});
...
// add Tab3
TabSpec tab3 = tabHost.newTabSpec(LIST3_TAB_TAG).setIndicator(LIST3_TAB_TAG).setContent(new TabContentFactory() {
public View createTabContent(String arg0) {
return layoutTab3;
}
});
tabHost.addTab(tab3);
layoutTab3.setVisibility(View.INVISIBLE);
...
}
}
MY R.layout.main:
<?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">
<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">
<ListView android:id="#+id/list1" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_weight="1">
</ListView>
<ListView android:id="#+id/list2" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_weight="1">
</ListView>
<RelativeLayout android:id="#+id/running_app_relative_layout"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout android:orientation="horizontal"
android:id="#+id/coco" android:layout_alignParentTop="true"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<ListView android:id="#+id/running_app_listview"
android:scrollbars="vertical" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_gravity="fill_vertical"
android:layout_alignParentTop="true"></ListView>
</LinearLayout>
</RelativeLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
I've figured out that when a custom ListView contains focusable elements, onListItemClick won't work (I think it's the expected behaviour). So I've just removed the focus from the custom view and it did the trick. In other words, I added the following commands to my view:
android:focusable="false"
android:focusableInTouchMode="false"
The full explanation is avaiable here: How to fire onListItemClick in Listactivity with buttons in list?
Related
I have a recyclerview list. Each item in the recyclerview contains the following layout. Later when one clicks on the sample1 id, then sample3.xml should get inserted inbetween sample1 and sample2. For that I have created a linearlayout with id insertat in this layout.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="fill_parent"
android:layout_height="40dp"
android:id="#+id/sample1"
android:text="Sample1"/>
<LinearLayout
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/insertat">
</LinearLayout>
<TextView
android:layout_width="fill_parent"
android:layout_height="40dp"
android:id="#+id/sample2"
android:text="Sample2"/>
</LinearLayout>
onclicking id sample1 I want to insert a layout file sample3.xml inside linearlayout id insertat.
sample3.xml is as follows
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/toinsert">
<TextView
android:layout_width="fill_parent"
android:layout_height="40dp"
android:text="Sample1"
android:id="#+id/sample3"/>
</LinearLayout>
How can I achieve this in recyclerview code.
I did not get exact requirement but , if you want just visible the view after on click, you can keep your layout by merge both as like below and can visible and invisible based on click event.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="fill_parent"
android:layout_height="40dp"
android:id="#+id/sample1"
android:text="Sample1"/>
<LinearLayout
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"
android:id="#+id/insertat">
<TextView
android:layout_width="fill_parent"
android:layout_height="40dp"
android:text="Sample1"
android:id="#+id/sample3"/>
</LinearLayout>
<TextView
android:layout_width="fill_parent"
android:layout_height="40dp"
android:id="#+id/sample2"
android:text="Sample2"/>
</LinearLayout>
LinearLayout layout = (LinearLayout)findViewbyId(R.id.insertat);
mKeepPlayingButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
layout.setVisibility(View.visible);
}
});
First get a reference of the insertat:
LinearLayout insertAtView = (LinearLayout) findViewById(R.id.insertat);
Inflate sample3 view:
View sample3View = getLayoutInflater().inflate(R.layout.sample3, insertAtView, false);
Then add sample3 to insertat:
insertAtView.addView(sample3View);
Full code:
findViewById(R.id.sample1).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
LinearLayout insertAtView = (LinearLayout) findViewById(R.id.insertat);
View sample3View = getLayoutInflater().inflate(R.layout.sample3, insertAtView, false);
insertAtView.addView(sample3View);
}
});
I am trying to have the content of the ListView centered when displayed in a dialog.
This is my code to show the ListView
String[] myItems = {"item1", "item2", "item3"};
ArrayAdapter<String> adapter = new ArrayAdapter<String>( this, R.layout.setting_layout, myItems);
ListView list = (ListView) deleteDialog.findViewById(R.id.listView1);
list.setAdapter(adapter);
list.setFadingEdgeLength(5);
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> paret, View viewClicked, int position, long id) {
// TODO Auto-generated method stub
}
}
And this is the xml part:
TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/textView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:layout_gravity="center"
android:textSize="25sp"
and this is the layout of delete dialog:
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal" >
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/listView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:dividerHeight="5dp"
android:gravity="center">
</ListView>
Its running but the content is always displayed to left.
I tried this: How to set the text at center in ListView android application?
but it didn't work.
Hope anyone can guide me through.
this will work for u
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/listView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:dividerHeight="5dp"
android:gravity="center">
</ListView>
You can try with
android:layout_gravity="center_vertical|center_horizontal"
I hope it helps
Change your LinearLayout to:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal">
So I have a ListView inside my TabHost and I want to redrow its content every time I change the tab. Nevertheless I never get the list drawed.
My xml file looks like:
<?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" />
<!-- Dishes Panel -->
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/dishSelector"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
tools:context=".MenuSelectorActivity" />
</LinearLayout>
</TabHost>
And my TabActivity:
public class MenuSelectorActivity extends TabActivity implements TabHost.TabContentFactory{
private ListView dishSelector;
private DishSelectorAdapter dishSelectorAdapter;
private TabHost tabHost;
private DishDao dishDao;
private DishTypeDao dishTypeDao;
private Map<Integer, List<DishPojo>> dishesByType;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_menu_selector);
tabHost = getTabHost(); // The activity TabHost
tabHost.setup();
TabHost.TabSpec spec;
dishDao = new DishDao(this);
dishTypeDao = new DishTypeDao(this);
dishesByType = new HashMap<Integer, List<DishPojo>>();//new ArrayList<List<DishPojo>>();
List<DishType> types = dishTypeDao.list();
TextView dTypeNameView;
for(DishType dType : types){
dishesByType.put(dType.getId().hashCode(), createDishPojoList(dishDao.list(
new String[]{DishDbContract.SQL_WHERE_CLAUSE_LIST_BY_TYPE}, new String[]{dType.getId()})));
}
tabHost.setCurrentTab(0);
for(DishType dType : types){
dTypeNameView = new TextView(this);
dTypeNameView.setText(dType.getDescription());
spec = tabHost.newTabSpec(dType.getId()).setIndicator(dTypeNameView).setContent(this);
tabHost.addTab(spec);
}
}
#Override
public View createTabContent(String tag) {
dishSelector = (ListView) findViewById(R.id.dishSelector);
if(dishSelectorAdapter == null){
dishSelectorAdapter = new DishSelectorAdapter(this, dishesByType.get(tag.hashCode()));
}else{
dishSelectorAdapter.setDishToSelect(dishesByType.get(tag.hashCode()));
}
dishSelector.setAdapter(dishSelectorAdapter);
dishSelector.refreshDrawableState();
return dishSelector;
}
private List<DishPojo> createDishPojoList(List<Dish> dishes){
//creates a list of Pojos
}
}
The adpter DishSelectorAdapter has been already used in other situation and it works ok, so I don't think it is relevant here.
Thanks by hand.
Well well, it was not as hard as I've thought. The answer was just in front of my eyes.
I didn't put the ListView inside de FrameLayout. The correct code will be:
<?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" />
<!-- Dishes Panel -->
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/dishSelector"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
tools:context=".MenuSelectorActivity" />
</FrameLayout>
</LinearLayout>
</TabHost>
Still rest of the code has some issues to work about, but nothing I coudln't fix with a quick look.
I created a sample application to test how sliding menu works. Shown below in the screenshot is what i get as of now. But when I click on the categories button (shown in image below) I should get a secondary menu as shown in the zomato app's screenshot below. How can I do this ? Am I proceeding in the correct way or not?
my SlidingFragmentActivity :
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
con = this;
setSlidingActionBarEnabled(false);
setContentView(R.layout.main);
sm = getSlidingMenu();
sm.setMode(SlidingMenu.RIGHT);
sm.setShadowDrawable(R.drawable.shadowright);
sm.setTouchModeAbove(SlidingMenu.TOUCHMODE_NONE);
sm.setBehindScrollScale(1.0f);
sm.setShadowWidthRes(R.dimen.shadow_width);
sm.setBehindOffsetRes(R.dimen.slidingmenu_offset);
sm.setFadeDegree(0.5f);
//sm.setSecondaryMenu(R.layout.properties);
//sm.setSecondaryShadowDrawable(R.drawable.shadow);
setTitle("Sliding Bar");
// set the Behind View
setBehindContentView(R.layout.menu_frame);
FragmentTransaction t = this.getSupportFragmentManager()
.beginTransaction();
mFrag = new SampleListFragment();
t.replace(R.id.menu_frame, mFrag);
t.commit();
}
my SampleListFragment :
public class SampleListFragment extends SherlockFragment {
private static final String[] Radio_buttons = new String[] { "Distance",
"Rating" };
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.list, container, false);
ListView radio_list = (ListView) view.findViewById(R.id.RadioList);
Button categories = (Button) view.findViewById(R.id.sampleButton);
radio_list
.setAdapter(new ArrayAdapter<String>(MainActivity.con,
android.R.layout.simple_list_item_single_choice,
Radio_buttons));
radio_list.setItemsCanFocus(true);
radio_list.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
categories.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
MainActivity.sm.showSecondaryMenu();
}
});
return view;
}
}
main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="Sliding menu demo...!!!" />
</RelativeLayout>
menu_frame.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/menu_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
list.xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/scroller"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ffffff"
android:paddingLeft="10dp"
android:text="SEARCH"
android:textColor="#FF3300"
android:textSize="20dp" >
</TextView>
</LinearLayout>
<RelativeLayout
android:id="#+id/searchTextLayout"
android:layout_width="match_parent"
android:layout_height="50dip"
android:layout_marginBottom="20dip"
android:layout_marginLeft="20dip"
android:layout_marginRight="20dip"
android:layout_marginTop="20dip" >
<ImageButton
android:id="#+id/searchTextButton"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:background="#685E5C"
android:scaleType="fitCenter"
android:src="#drawable/abs__ic_search" />
<EditText
android:id="#+id/searchText"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_toRightOf="#id/searchTextButton"
android:background="#drawable/background_black_border_full"
android:padding="8dp"
android:textColor="#android:color/white" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ffffff"
android:paddingLeft="10dp"
android:text="SORT BY"
android:textColor="#FF3300"
android:textSize="20dp" >
</TextView>
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="134dp" >
<ListView
android:id="#+id/RadioList"
android:layout_width="match_parent"
android:layout_height="fill_parent" >
</ListView>
</RelativeLayout>
<Button
android:id="#+id/sampleButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Categories" />
</LinearLayout>
</ScrollView>
SlidingMenu does NOT do this, zomato uses a custom implementation.
SlidingMenu will let you have a menu on the left and the right, but not two on either side.
I would look at using a view pager or a custom implementation. EitherWay I don't know of anything out of the box to do this. I might be worth looking at Android Views for inspiration.
It's a bit late, but still let me post my answer in case it will help someone in future. If you want to show another menu you can use
setMode(SlidingMenu.LEFT_RIGHT);
setSecondaryMenu(R.layout.yourSecondMenu);
and in your button click
showSecondaryMenu(true);
and perform your actions in that class.
I was testing TabActivity with a list in each tab.
While running the app, the contents of the tabs gets overlapped like this.
After i click on the tabs the overlapping gets cleared.
Here is my code :
testtabs.xml layout :
<?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">
<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">
<ListView
android:id="#+id/list1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
</ListView>
<ListView
android:id="#+id/list2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
</ListView>
</FrameLayout>
</LinearLayout>
</TabHost>
And Test Activity
public class TabbedActivity extends TabActivity {
private static final String LIST1_TAB_TAG = "List1";
private static final String LIST2_TAB_TAG = "List2";
private ListView listView1;
private ListView listView2;
private TabHost tabHost;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.testtabs);
tabHost = getTabHost();
// setup list view 1
listView1 = (ListView) findViewById(R.id.list1);
// create some dummy strings to add to the list
List<String> list1Strings = new ArrayList<String>();
list1Strings.add("List 11");
list1Strings.add("List 12");
list1Strings.add("List 13");
list1Strings.add("List 14");
listView1.setAdapter(new ArrayAdapter(this, android.R.layout.simple_list_item_1, list1Strings));
// setup list view 2
listView2 = (ListView) findViewById(R.id.list2);
List<String> list2Strings = new ArrayList<String>();
list2Strings.add("Test2 List 21");
list2Strings.add("Testing 22");
list2Strings.add("More test 23");
list2Strings.add("Test Again 24");
listView2.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, list2Strings));
// add views to tab host
tabHost.addTab(tabHost.newTabSpec(LIST1_TAB_TAG).setIndicator(LIST1_TAB_TAG).setContent(new TabContentFactory() {
public View createTabContent(String arg0) {
return listView1;
}
}));
tabHost.addTab(tabHost.newTabSpec(LIST2_TAB_TAG).setIndicator(LIST2_TAB_TAG).setContent(new TabContentFactory() {
public View createTabContent(String arg0) {
return listView2;
}
}));
tabHost.setCurrentTab(0);
}
}
You can remove both ListView from xml layout and just create them in java code.
e.g. listView1 = new ListView(this);
Everything will be Ok.
Another solution I found is to add the following tag to both the listviews in the layout XML file:
android:visibility="invisible"
You are taking two ListView's in a FrameLayout that is the reason for your over-lapping.
If you want that you should have one ListView below the other keep the ListView's inside the LinearLayout like this,
<?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">
<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">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView
android:id="#+id/list1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
</ListView>
<ListView
android:id="#+id/list2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
</ListView>
</LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>