My question:
How do i view the lists for each tab separately? If I run it as is, when i select brooklyn, the same list from bronx displayed.
Another question. How do i make it so when i run the program, the list does not appear until you select whatever tab i choose.
package com.MTA_Transit;
import android.app.Activity;
import android.app.TabActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TabHost;
public class MTA_Transit extends TabActivity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TabHost mTabHost = getTabHost();
ListView bronx=(ListView)findViewById(R.id.bronx);
ListView brooklyn=(ListView)findViewById(R.id.brooklyn);
ArrayAdapter<String> adapter = new ArrayAdapter<String> (this,android.R.layout.simple_list_item_1,BRONX);
bronx.setAdapter(adapter);
ArrayAdapter<String> adapter1 = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,BROOKLYN);
brooklyn.setAdapter(adapter);
//Bronx Tab
mTabHost.addTab(mTabHost.newTabSpec("").setIndicator("Bronx",getResources().getDrawable(R.drawable.tab_one))
.setContent(R.id.bronx));
//Brooklyn Tab
mTabHost.addTab(mTabHost.newTabSpec("").setIndicator("Brooklyn",getResources().getDrawable(R.drawable.tab_two))
.setContent(R.id.brooklyn));
//Manhattan Tab
mTabHost.addTab(mTabHost.newTabSpec("").setIndicator("Manhattan",getResources().getDrawable(R.drawable.tab_three))
.setContent(R.id.textview3));
//Queens Tab
mTabHost.addTab(mTabHost.newTabSpec("").setIndicator("Queens",getResources().getDrawable(R.drawable.tab_four))
.setContent(R.id.textview4));
//Staten Island Tab
mTabHost.addTab(mTabHost.newTabSpec("").setIndicator("Staten Island",getResources().getDrawable(R.drawable.tab_five))
.setContent(R.id.textview5));}
static final String[] BRONX = new String[] {
"Bx1 Grand Concourse","Bx2 Grand Concourse","Bx3 University Avenue/West 181 Street","Bx4","Bx4A","Bx5","Bx6","Bx7","Bx8","Bx9","Bx10","Bx11","Bx12","Bx13",
"Bx15 3 Avenue/125 Street","Bx16 East 233 Street/Nereid Avenue","Bx17","Bx18","Bx19","Bx20","Bx21","Bx22","Bx23","Bx24" ,"Bx26","Bx27"
};
static final String[] BROOKLYN = new String[] {
"Bx1 Grand Concourse"
};
}
<?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/bronx" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_weight="1"
>
</ListView>
<ListView android:id="#+id/brooklyn" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_weight="1"
>
</ListView>
<ListView android:id="#+id/list3" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_weight="1"
>
</ListView>
<ListView android:id="#+id/list4" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_weight="1"
>
</ListView>
<TextView
android:id="#+id/textview1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="" />
<TextView
android:id="#+id/textview2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="" />
<TextView
android:id="#+id/textview3"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="" />
<TextView
android:id="#+id/textview4"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="" />
<TextView
android:id="#+id/textview5"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="" />
</FrameLayout>
</LinearLayout>
</TabHost>
Each tab should have its own activity. Please see this tutorial. In each activity you will define its corresponding view separately, so you would have separate list views.
Related
Hi I want to create a responsive scrollable grids. As I search, I came across some codes. I tweaked this code to allow scrolling of the grids. The code creates a 2 column grids and 4 rows with cardViews. The cardViews shrinks to allow more cards into the viewport rather than scrolling. Am open to any ideas and alternative methods to make this work.Thanks in advance.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:scrollbars="vertical"
android:fillViewport="true">
<LinearLayout
android:orientation="vertical"
android:weightSum="10"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_weight="2"
android:layout_width="match_parent"
android:layout_height="0dp">
<TextView
android:id="#+id/textGrid"
android:text="Games"
android:textSize="34sp"
android:textColor="#android:color/black"
android:layout_centerInParent="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
<android.support.v7.widget.GridLayout
android:id="#+id/gridView"
android:layout_weight="8"
app:columnCount="2"
app:rowCount="2"
android:padding="14dp"
app:alignmentMode="alignMargins"
app:columnOrderPreserved="false"
android:layout_width="match_parent"
android:layout_height="0dp"
>
<android.support.v7.widget.CardView
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginBottom="16dp"
app:cardCornerRadius="8dp"
app:cardElevation="8dp"
app:layout_columnWeight="1"
app:layout_rowWeight="1">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|center_vertical"
android:layout_margin="16dp"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:src="#drawable/sampleimage" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Grid One
android:textAlignment="center"
android:textColor="#000"
android:textSize="18sp"
android:textStyle="bold" />
</LinearLayout>
</android.support.v7.widget.CardView>
</android.support.v7.widget.GridLayout>
</LinearLayout>
</ScrollView>
I have a pattern like that in one of my apps. Tickets get added to the 3-wide grid and you can scroll the grid. Here is the code I use.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/your_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:baselineAligned="false"
android:orientation="vertical">
<ScrollView
android:id="#+id/your_scrollview"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginLeft="2dip"
android:layout_gravity="center_horizontal">
<LinearLayout
android:id="#+id/your_grid"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:gravity="center"
android:orientation="vertical"
android:visibility="visible">
<GridView
android:id="#+id/gridViewTickets"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:numColumns="3"
android:padding="8dp"
android:horizontalSpacing="8dp"
android:verticalSpacing="8dp"
android:minHeight="250dip"
android:gravity="center_horizontal"
android:layout_gravity="center_horizontal">
</GridView>
</LinearLayout>
</ScrollView
</LinearLayout>
After a lot of research I came across RecyclerView. It was a little confusing but it worked fine. I had to use two(2) layouts (activity_main.xml and row_data.xml) with MainActivity.java.
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="MainActivity">
<GridView
android:id="#+id/gridview"
android:numColumns="2"
android:verticalSpacing="1dp"
android:background="#e5e5e5"
android:horizontalSpacing="1dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</GridView>
</RelativeLayout>
row_data.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.CardView
android:id="#+id/gridviewdata"
android:layout_margin="12dp"
app:cardCornerRadius="12dp"
app:cardElevation="6dp"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_centerInParent="true"
>
<LinearLayout
android:orientation="vertical"
android:padding="16dp"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/images"
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:src="#drawable/apple" />
<TextView
android:id="#+id/fruits"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="Apple something"
android:textStyle="normal|italic"
android:textSize="25dp" />
</LinearLayout>
</android.support.v7.widget.CardView>
</RelativeLayout>
MainActivity.java
package com.example.gridrecycler;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
GridView gridView;
String[] fruitNames = {"Apple","Orange","strawberry","Melon","Kiwi","Banana"};
int[] fruitImages = {R.drawable.apple,R.drawable.oranges,R.drawable.strawberry,R.drawable.watermelon,R.drawable.kiwi,R.drawable.banana};
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//finding listview
gridView = findViewById(R.id.gridview);
CustomAdapter customAdapter = new CustomAdapter();
gridView.setAdapter(customAdapter);
gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
// Toast.makeText(getApplicationContext(),fruitNames[i],Toast.LENGTH_LONG).show();
Intent intent = new Intent(getApplicationContext(),GridItemActivity.class);
intent.putExtra("name",fruitNames[i]);
intent.putExtra("image",fruitImages[i]);
startActivity(intent);
}
});
}
private class CustomAdapter extends BaseAdapter {
#Override
public int getCount() {
return fruitImages.length;
}
#Override
public Object getItem(int i) {
return null;
}
#Override
public long getItemId(int i) {
return 0;
}
#Override
public View getView(int i, View view, ViewGroup viewGroup) {
View view1 = getLayoutInflater().inflate(R.layout.row_data,null);
//getting view in row_data
TextView name = view1.findViewById(R.id.fruits);
ImageView image = view1.findViewById(R.id.images);
name.setText(fruitNames[i]);
image.setImageResource(fruitImages[i]);
return view1;
}
}
}
I watched diff tuts to come up with this. Am now doubting whether it comforms to best practices. Thanks to you all for your suggestions.
I have the following code that is a dynamic listview where you type in the textbox and click the add button and its added to the listview below. Listview is a custom listview with 2 textviews. Somehow the code adds the first item and then does not add the rest. The arraylist gets the item, i call adapter.notifyDataSetChanged(); and yet still the listview does not get updated. What am i doing wrong?
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;
public class ManageComplaintsActivity extends DashboardActivity {
EditText txtAddComplaint;
ListView lvComplaintsList;
Button btnAddComplaint;
private SimpleAdapter adapter;
private int count = 1;
private ArrayList<Map<String, String>> list = new ArrayList<Map<String, String>>();;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_manage_complaints);
setTitleFromActivityLabel (R.id.title_text);
txtAddComplaint= (EditText) findViewById(R.id.txtAddComplaint);
lvComplaintsList= (ListView) findViewById(R.id.lvComplaintsList);
btnAddComplaint = (Button)findViewById(R.id.btnAddComplaint);
String[] from = { "complaint", "complaintid" };
int[] to = { R.id.lblC, R.id.lblCID };
adapter = new SimpleAdapter (this, list, R.layout.activity_manage_complaints_row, from, to);
lvComplaintsList.setAdapter(adapter);
btnAddComplaint.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
HashMap<String, String> item = new HashMap<String, String>();
item.put("complaint", txtAddComplaint.getText().toString());
item.put("complaintid", Integer.toString(count));
list.add(item);
adapter.notifyDataSetChanged();
count++;
txtAddComplaint.setText("");
Toast.makeText(getApplicationContext(),Integer.toString(list.size()), Toast.LENGTH_SHORT).show();
}
});
lvComplaintsList.setOnItemClickListener(new OnItemClickListener(){
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Toast.makeText(getApplicationContext(),
((TextView)view.findViewById(R.id.lblC)).getText(), Toast.LENGTH_SHORT).show();
}
});
}
}
This is the 2 xml files
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical" >
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="10dip"
android:shrinkColumns="1"
android:stretchColumns="1" >
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<EditText
android:id="#+id/txtAddComplaint"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3" />
<Button
android:id="#+id/btnAddComplaint"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Add" />
</TableRow>
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/txtComplaintLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="List of Complaints : "
android:textAppearance="?android:attr/textAppearanceLarge"
android:paddingBottom="20dp"/>
</TableRow>
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ListView
android:id="#+id/lvComplaintsList"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_span="2" />
</TableRow>
</TableLayout>
</ScrollView>
</LinearLayout>
This is the listviewrow xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="#+id/lblC"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
/>
<TextView
android:id="#+id/lblCID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
/>
</RelativeLayout>
As you can see in documentation to SimppleAdapter it is
An easy adapter to map static data to views defined in an XML file.
I believe that you can find any tricky way to add data dynamically. But I'm not sure that you have to do it like this. Try to use ArrayAdapter instead. By default it binds T.toString() values to single TextView, but you can override getView(int, View, ViewGroup) to return the type of view you want.
I changed the main xml file as follows
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/LinearLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/LinearLayout02"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<EditText
android:id="#+id/txtAddComplaint"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" >
</EditText>
<Button
android:id="#+id/btnAddComplaint"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add to Listview" >
</Button>
</LinearLayout>
<ListView
android:id="#+id/lvComplaintsList"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
I had used a table layout and the listview was in one of the rows.
Hope this helps someone .
Hello all this is my code for the tab layout in to android i want them in to bottom of the scrren currently it shows me at top of the screen
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_alignParentBottom="true"
android:gravity="bottom">
<TabHost 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">
<HorizontalScrollView android:scrollbars="none"
android:layout_width="fill_parent" android:layout_height="wrap_content">
<TabWidget android:id="#android:id/tabs"
android:layout_alignParentBottom="true" android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</HorizontalScrollView>
<FrameLayout android:id="#android:id/tabcontent"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:padding="5dp" />
</LinearLayout>
</TabHost>
</LinearLayout>
tab.xml
<?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="fill_parent"
android:background="#drawable/tab_background_selector" android:gravity="center"
android:orientation="vertical" android:padding="5dp"
android:layout_alignParentBottom="true" >
<ImageView android:id="#+id/tab_icon" android:layout_width="30dp"
android:layout_height="30dp" android:scaleType="fitCenter" />
<TextView android:id="#+id/tab_text" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:singleLine="true"
android:textStyle="bold" android:gravity="center_horizontal"
android:textSize="10sp" android:padding="3dip" android:ellipsize="marquee"
android:textColor="#drawable/tab_text_selector"
android:layout_alignParentBottom="true" />
</LinearLayout>
this is my activity class
TestActivity.java
import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TabHost;
import android.widget.TextView;
import android.widget.TabHost.TabSpec;
public class TestActivity extends TabActivity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.maiin);
final TabHost tabHost = (TabHost) getTabHost();
tabHost.addTab(createTab(MobiintheMorningActivity.class,
"Welcome", "Welcome", R.drawable.icon));
tabHost.setCurrentTab(0);
tabHost.getTabWidget().getChildAt(0).getLayoutParams().width = 85;
}
private TabSpec createTab(final Class<?> intentClass, final String tag,
final String title, final int drawable)
{
final Intent intent = new Intent().setClass(this, intentClass);
final View tab = LayoutInflater.from(getTabHost().getContext()).
inflate(R.layout.tab, null);
((TextView)tab.findViewById(R.id.tab_text)).setText(title);
((ImageView)tab.findViewById(R.id.tab_icon)).setImageResource(drawable);
return getTabHost().newTabSpec(tag).setIndicator(tab).setContent(intent);
}
}
here i've used android:layout_alignParentBottom="true" but no effects at all what should i do? what thing i am missing? thanks in advance :Pragna
See the solution to put the tab bar at the bottom.
Change the position of FrameLayout and widget in your xml.I think that my help you
hi please help
actually i m trying to make list view as invisible
but its showing the listview and gridview both at one time please help in solving it.
here is the code.
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
Gallery gallery = (Gallery) findViewById(R.id.gallery1);
lst=(ListView)findViewById(R.id.list);
lst.setVisibility(View.INVISIBLE);
// ViewManager hi=(ViewManager)getBaseContext().getSystemService(WINDOW_SERVICE );
gallery.setAdapter(new ImageAdapter(this));
final GridView gridView = (GridView) findViewById(R.id.gridview);
mInflater = (LayoutInflater) getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
data = new Vector<RowData>();
for(int i=0;i<title.length;i++){
try {
rd = new RowData(i,title[i],detail[i]);
} catch (ParseException e) {
e.printStackTrace();
}
data.add(rd);
lst.setAdapter(new CustomAdapter(this, R.layout.list,R.id.title,data));
}
gridView.setAdapter(new ImageAd(this));
final TabHost tabs=(TabHost)findViewById(R.id.tabhost);
tabs.setup();
final TabHost.TabSpec spec=tabs.newTabSpec("buttontab");
final TabHost.TabSpec spec1=tabs.newTabSpec("btn");
spec.setContent(R.id.list);
lst.setVisibility(View.INVISIBLE);
spec1.setContent(R.id.buttontab);
spec.setIndicator("tab1");
spec1.setIndicator("tab1");
tabs.addTab(spec);
tabs.setCurrentTab(0);
tabs.getTabWidget().getChildAt(0).setLayoutParams(new
LinearLayout.LayoutParams(30,30));
spec.setIndicator("tab2");
tabs.addTab(spec);
tabs.getTabWidget().getChildAt(1).setLayoutParams(new
LinearLayout.LayoutParams(30,30));
tabs.setOnTabChangedListener(new OnTabChangeListener(){
#Override
public void onTabChanged(String tabId) {
if(tabId=="buttontab")
and here is xml file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="50px"
android:orientation="horizontal">
<Button
android:id="#+id/login"
android:layout_width="80px"
android:layout_height="wrap_content"
android:text="Login"
/>
<TextView
android:paddingLeft="80px"
android:id="#+id/search"
android:layout_width="40px"
android:text="Search"
android:layout_height="wrap_content"
/>
<EditText
android:layout_width="100px"
android:layout_height="wrap_content"
/>
</LinearLayout>
<Gallery
android:id="#+id/gallery1"
android:layout_width="fill_parent"
android:layout_height="50px" />
<TabHost android:id="#+id/tabhost"
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"
android:paddingTop="62px">
<ListView android:id="#+id/list"
android:layout_width="fill_parent"
android:layout_height="200px" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/gridview"
android:layout_width="fill_parent"
android:layout_height="200px"
android:numColumns="4"
android:verticalSpacing="5px"
android:horizontalSpacing="5px"
android:columnWidth="60dp"
android:stretchMode="columnWidth"
android:gravity="center"
/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<Button
android:id="#+id/buttontab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/icon"/>
<ImageButton
android:id="#+id/hello1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/icon"/>
<ImageButton
android:id="#+id/hello3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/icon"/>
<ImageButton
android:id="#+id/hello4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/icon"/>
<ImageView
android:id="#+id/hello5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/icon"/>
</LinearLayout>
</LinearLayout>>
</FrameLayout>
</TabHost>
</LinearLayout>
so please help to make listview as invisiblei know its a very little mistake but unable to solve the error
Try View.GONE instead of View.INVISIBLE
Since you are doing this in onCreate you could do it in your XML:
<ListView
android:id="#+id/list"
android:layout_width="fill_parent"
android:layout_height="200px"
android:visibility="gone"
/>
What syntax (xml and java) should I use to create a View, which would have a couple of buttons ("Next" and "Back") at the top of the screen, and a List, located below the buttons?
I have tried the following, but it did not work at all:
main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/hello"
/>
<Button android:text="#+id/Button01" android:id="#+id/Button01"
android:layout_width="wrap_content" android:layout_height="wrap_content">
</Button>
<ListView android:id="#+id/ListView01" android:layout_width="fill_parent"
android:layout_height="fill_parent">
</ListView>
</LinearLayout>
FirstScreen.java:
public class FirstScreen extends ListActivity {
/** Called when the activity is first created. */
String [] entries = {"one","two","three"};
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ArrayAdapter<String> adapter =
new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,entries);
ListView lv = new ListView(this,null,R.id.ListView01);
setListAdapter(adapter);
}
}
Here is an XML layout that should work :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Hello"
/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button
android:id="#+id/next"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="Next"
android:layout_weight="1"
android:textSize="16dip"/>
<Button
android:id="#+id/back"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="Back"/>
</LinearLayout>
<ListView
android:id="#+id/your_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</ListView>
</LinearLayout>
And for the Java code.
...
String[] entries = { "one", "two", "three" };
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, entries);
ListView lv = (ListView) findViewById(R.id.your_list);
lv.setAdapter(adapter);
...
I hope this will answer your question.
you need to use this for your listview ID if you want to use a ListActivity
android:id="#id/android:list"