listview id is not detected - android

I am trying to import my ListView but for some reason my program cannot detect my listview ID. I have tried cleaning project and restarting eclipse but i am getting the same results
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.firstlist);
testcontacts = getResources()
.getStringArray(R.array.testcontacts_array);
aa = new MessageView();
lv = (ListView) findViewById(R.id.list);
lv.setAdapter(aa);
lv.setTextFilterEnabled(true);
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// When clicked, show a toast with the TextView text
Toast.makeText(getApplicationContext(),
((TextView) view).getText(), Toast.LENGTH_SHORT).show();
}
});
}
Here is my Listview xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/top_control_bar"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_weight="1"
android:background="#cc252a"
android:paddingBottom="10dp"
android:paddingLeft="10dp"
android:paddingTop="10dp"
android:text="This will be Changed"
android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>
<LinearLayout
android:id="#+id/bottom_control_bar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" >
</LinearLayout>
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_above="#id/bottom_control_bar"
android:layout_below="#id/top_control_bar"
android:choiceMode="multipleChoice" >
</ListView>
</RelativeLayout>
Here are my list view items format:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:padding="6dip" >
<ImageView
android:id="#+id/icon1"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentTop="true"
android:layout_marginRight="6dip"
android:src="#drawable/ic_launcher" />
<TextView
android:id="#+id/secondLine"
android:layout_width="fill_parent"
android:layout_height="26dip"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_toRightOf="#id/icon1"
android:ellipsize="marquee"
android:singleLine="true"
android:text="Some more information" />
<TextView
android:id="#+id/firstLine"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="#id/secondLine"
android:layout_alignParentTop="true"
android:layout_alignWithParentIfMissing="true"
android:layout_toRightOf="#id/icon1"
android:gravity="center_vertical"
android:text="Some Information" />
<ImageView
android:id="#+id/icon2"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginRight="6dip"
android:src="#drawable/ic_launcher" />
</RelativeLayout>

Isn't it supposed to be
<ListView
android:id="#+id/list"
instead of
<ListView
android:id="#android:id/list"

Related

Button overriding listview items and how to add textview just above listview

I have a listview between header and button, I want to add textview just above listview and button to align properly so that button do not override listview items. How can i do that? Not sure what is the issue with xml layout
layout.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#e7ebee"
android:gravity="center"
android:orientation="vertical"
android:weightSum="1">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="452dp"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/mainheader"
android:layout_width="fill_parent"
android:layout_height="52dp"
android:background="#0a2436">
<RelativeLayout
android:id="#+id/subheader"
android:layout_width="wrap_content"
android:layout_height="52dp" >
<ImageView
android:id="#+id/back"
android:layout_width="40dip"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:background="#drawable/my_highlight_drawable"
android:src="#drawable/back" />
<ImageView
android:id="#+id/inboxheader"
android:layout_width="2dip"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginRight="5dp"
android:layout_toRightOf="#+id/back"
android:background="#85929B"
android:paddingBottom="15dip"
android:paddingTop="15dip" />
</RelativeLayout>
<ImageView
android:id="#+id/windowtitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:contentDescription="#null"
android:src="#drawable/logo" />
</RelativeLayout>
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:divider="#android:color/darker_gray"
android:dividerHeight="1dip"
android:drawSelectorOnTop="false"
android:focusable="false"
android:paddingTop="0dip" />
<TextView
android:id="#+id/android:empty"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:text="No Data Available"
android:visibility="invisible" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center" >
<TableLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerInParent="true"
android:gravity="bottom">
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#092435"
android:gravity="center_horizontal" >
<Button
android:id="#+id/btnManualLookup"
android:layout_width="0dp"
android:layout_weight="1"
android:background="#4982AE"
android:gravity="center"
android:padding="15dip"
android:text="Submit"
android:textColor="#ffffff" />
</TableRow>
</TableLayout>
</LinearLayout>
</LinearLayout>
Have you considered adding a headerview to listview. You could actually use a layout as header for listview. This way, you views on header will never overflow on to listview.
final ListView lstVRHDetails = (ListView) getActivity().findViewById(R.id.listview);
LayoutInflater inflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View headerView = inflater.inflate(<header layout>, new LinearLayout(getActivity()), false);
headerView.findViewById(R.id.rlFromDate).setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
}
});
headerView.findViewById(R.id.rlToDate).setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
}
});
headerView.findViewById(R.id.imgUpdate).setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
}
});
headerView.setLayoutParams(new ListView.LayoutParams(ListView.LayoutParams.MATCH_PARENT, ListView.LayoutParams.WRAP_CONTENT));
lstVRHDetails.addHeaderView(headerView);

getChildAt() InvocationTargetException

In xml of row_layout I've set a delete button as follows
row_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/rowlayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="0dp"
android:background="#ffffff"
android:baselineAligned="false"
android:orientation="horizontal"
android:paddingLeft="10sp"
android:weightSum="100" >
<LinearLayout
android:id="#+id/Layout"
android:layout_width="150sp"
android:layout_height="50dp"
android:layout_weight="90"
android:orientation="vertical" >
<TextView
android:id="#+id/firstTextView"
android:layout_width="150sp"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_marginTop="10sp"
android:gravity="top"
android:text="Activity"
android:textColor="#000" />
<TextView
android:id="#+id/firstTextView2"
android:layout_width="150sp"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:gravity="top"
android:text="Sub-Activity"
android:textColor="#000" />
</LinearLayout>
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:src="#drawable/edit" />
<ImageView
android:id="#+id/delete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:onClick="onClickDelete"
android:src="#drawable/neg" />
</LinearLayout>
here is onClickDelete method
public void onClickDelete(View v)
{
ListView lvItems = getListView();
//get the row the clicked button is in
LinearLayout vwParentRow = (LinearLayout)v.getParent();
TextView child = (TextView) vwParentRow.getChildAt(0);
child.setText("Delete Clicked");
}
When i press delete, it shows invocationtargetexception at (TextView child = (TextView) vwParentRow.getChildAt(0);)
Sorry if this is very basic mistake. I am new to android.
Thank you for your reply.
It's better
TextView child = (TextView)findViewById("yourtextfieldIDHere");
child.setText("Delete Clicked");

GridView only shows first row

i have a gridview to show images with button, but i have a problem, it only shows the first row, and i send it data for 3 rows..
This is my layout code:
<?xml version="1.0" encoding="utf-8"?><!-- To make screen scroll in vertical direction -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:bootstrapthumbnail="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true"
android:background="#drawable/fondodroid2"
android:orientation="vertical">
<!-- Main layout -->
<ScrollView
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:id="#+id/scrollView">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#fefdff"
android:layout_marginLeft="#dimen/login_activity_horizontal_margin"
android:layout_marginRight="#dimen/login_activity_horizontal_margin"
android:layout_marginTop="#dimen/login_activity_vertical_margin"
android:padding="#dimen/login_activity_horizontal_margin"
android:id="#+id/linearLayout">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:baselineAligned="true"
android:paddingTop="0dp"
android:paddingBottom="0dp"
android:layout_marginBottom="#dimen/login_activity_vertical_margin"
android:weightSum="1">
<ImageView
android:layout_width="#dimen/login_activity_logo"
android:layout_height="#dimen/login_activity_logo"
android:id="#+id/imageView"
android:src="#drawable/logo"
android:contentDescription="Icon GG"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="#string/files"
android:id="#+id/textView"
android:textSize="#dimen/login_activity_text"
android:textColor="#android:color/black"
android:textStyle="bold"
android:layout_marginTop="10dp"
android:layout_alignParentTop="true"
android:layout_toRightOf="#+id/imageView"
android:layout_marginLeft="10dp" />
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:id="#+id/relativeLayout">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_centerInParent="true"
android:background="#686868"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#android:color/white"
android:text="#string/sign_string"
android:textSize="#dimen/login_activity_vertical_margin"
android:textStyle="bold" />
</LinearLayout>
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:id="#+id/linearSign"
android:layout_centerInParent="true"
android:background="#cccccc"
android:visibility="gone">
<ImageView
android:id="#+id/sign_thumb"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_margin="3dp"></ImageView>
<LinearLayout
android:orientation="horizontal"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_below="#+id/sign_thumb"
android:layout_alignEnd="#+id/sign_thumb">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Eliminar"
android:id="#+id/deleteButton"
android:background="#cc6b67"
android:textStyle="bold"
android:layout_marginBottom="8dp" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:id="#+id/relativeLayout2"
android:layout_marginTop="16dp">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_centerInParent="true"
android:background="#686868"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#android:color/white"
android:text="#string/images"
android:textSize="#dimen/login_activity_vertical_margin"
android:textStyle="bold" />
</LinearLayout>
</RelativeLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/linearLayout2">
<GridView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="#+id/gridImages"
android:numColumns="2"
android:layerType="hardware"
android:verticalSpacing="1dp"
android:horizontalSpacing="1dp" />
</LinearLayout>
</LinearLayout>
<ImageView
android:layout_width="#dimen/login_activity_logo_h"
android:layout_height="#dimen/login_activity_logo_v"
android:id="#+id/imageView2"
android:src="#drawable/logo"
android:layout_below="#+id/linearLayout"
android:layout_alignRight="#+id/linearLayout"
android:layout_marginTop="#dimen/login_activity_vertical_margin"
android:layout_marginBottom="#dimen/login_activity_vertical_margin"
android:contentDescription="#string/logo" />
</RelativeLayout>
</ScrollView>
</LinearLayout>
In the adapter i dont have any strangle, but if you need i copy it here..I try with fill_parent wrap_content etc but nothing works..
Edit: the adapter code:
public class GridAdapter extends BaseAdapter {
private LayoutInflater inflater;
private Activity activity;
private List<String> images = new ArrayList<String>();
private OnDeleteItem mListener;
public interface OnDeleteItem {
public void onDeleteItemClick(String path);
}
public GridAdapter(Activity inyectActivity, List<String> listImages) {
activity = inyectActivity;
images = listImages;
inflater = LayoutInflater.from(activity);
mListener = (ReviewFilesActivity) activity;
}
public void notifyDataSetChanged(List<String> dataImages) {
images = dataImages;
super.notifyDataSetChanged();
}
public View getView(final int position, View convertView, ViewGroup parent) {
GridViewHolder vHolder;
if (convertView == null) {
convertView = inflater.inflate(R.layout.grid_view, null);
vHolder = new GridViewHolder(convertView, mListener);
vHolder.image.setImageBitmap(ImagesUtilities.decodeSampledBitmapFromResource(images.get(position), 400, 400));
vHolder.path = images.get(position);
vHolder.delete.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
mListener.onDeleteItemClick(images.get(position));
}
});
} else {
vHolder = (GridViewHolder) convertView.getTag();
}
return convertView;
}
#Override
public int getCount() {
return images.size();
}
#Override
public Object getItem(int position) {
return null;
}
#Override
public long getItemId(int position) {
return 0;
}
static class GridViewHolder {
public GridViewHolder(View view, OnDeleteItem listener) {
ButterKnife.inject(this, view);
}
#InjectView(R.id.grid_item_image)
ImageView image;
#InjectView(R.id.deleteButton)
Button delete;
String path;
public String getPath() {
return path;
}
}
}
Edit2:
I did more simply the XML, but the rows dont show.
<?xml version="1.0" encoding="utf-8"?><!-- To make screen scroll in vertical direction -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true"
android:background="#drawable/fondodroid2"
android:orientation="vertical">
<!-- Main layout -->
<ScrollView
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:id="#+id/scrollView">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#fefdff"
android:layout_marginLeft="#dimen/login_activity_horizontal_margin"
android:layout_marginRight="#dimen/login_activity_horizontal_margin"
android:layout_marginTop="#dimen/login_activity_vertical_margin"
android:padding="#dimen/login_activity_horizontal_margin"
android:id="#+id/linearLayout">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:baselineAligned="true"
android:paddingTop="0dp"
android:paddingBottom="0dp"
android:layout_marginBottom="#dimen/login_activity_vertical_margin"
android:weightSum="1">
<ImageView
android:layout_width="#dimen/login_activity_logo"
android:layout_height="#dimen/login_activity_logo"
android:id="#+id/imageView"
android:src="#drawable/logo"
android:contentDescription="Icon GG"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="#string/files"
android:id="#+id/textView"
android:textSize="#dimen/login_activity_text"
android:textColor="#android:color/black"
android:textStyle="bold"
android:layout_marginTop="10dp"
android:layout_alignParentTop="true"
android:layout_toRightOf="#+id/imageView"
android:layout_marginLeft="10dp" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:id="#+id/relativeLayout"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#android:color/white"
android:text="#string/sign_string"
android:textSize="#dimen/login_activity_vertical_margin"
android:textStyle="bold"
android:background="#686868"
android:layout_alignParentEnd="true"
android:layout_alignParentStart="true"
android:gravity="center"
android:id="#+id/textView3" />
<ImageView
android:id="#+id/sign_thumb"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_centerHorizontal="true"
android:layout_alignParentEnd="false"
android:visibility="gone" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Eliminar"
android:id="#+id/deleteButton"
android:background="#cc6b67"
android:textStyle="bold"
android:layout_alignBottom="#+id/textView3"
android:layout_alignParentStart="true"
android:visibility="gone" />
</LinearLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:id="#+id/relativeLayout2"
android:layout_marginTop="16dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:textColor="#android:color/white"
android:text="#string/images"
android:textSize="#dimen/login_activity_vertical_margin"
android:textStyle="bold"
android:background="#686868"
android:layout_alignParentEnd="true"
android:layout_alignParentStart="true"
android:gravity="center"
android:id="#+id/textView2" />
<GridView
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:id="#+id/gridImages"
android:numColumns="2"
android:verticalSpacing="1dp"
android:horizontalSpacing="1dp"
android:layout_alignParentLeft="false"
android:layout_marginLeft="0dp"
android:layout_below="#+id/textView2" />
</RelativeLayout>
</LinearLayout>
<ImageView
android:layout_width="#dimen/login_activity_logo_h"
android:layout_height="#dimen/login_activity_logo_v"
android:id="#+id/imageView2"
android:src="#drawable/logo"
android:layout_below="#+id/linearLayout"
android:layout_alignRight="#+id/linearLayout"
android:layout_marginTop="#dimen/login_activity_vertical_margin"
android:layout_marginBottom="#dimen/login_activity_vertical_margin"
android:contentDescription="#string/logo" />
</RelativeLayout>
</ScrollView>
</LinearLayout>
Here is some simplified example to achieve needed layout
<?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" >
<LinearLayout
android:id="#+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageView
android:id="#+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_icon" />
<TextView
android:id="#+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:id="#+id/relativeLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="horizontal" >
<TextView
android:id="#+id/textView3"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<ImageView
android:id="#+id/sign_thumb"
android:layout_width="match_parent"
android:layout_height="100dp"
android:src="#drawable/ic_icon" />
<Button
android:id="#+id/deleteButton"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<TextView
android:id="#+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<GridView
android:id="#+id/gridImages"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:numColumns="2" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/ic_icon" />
</LinearLayout>

Android - 2 ListView in same row

I use ListView to populate my Menu and Price.
I have 2 ListViews basically: one for Menu and another one for Price.
How do I show tow ListViews in same row as per the image below?
Please advise.
viewmenu.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:orientation="vertical"
android:background="#drawable/menu_splashscreen_bg">
<TextView
android:id="#+id/TextView01"
android:layout_height="wrap_content"
android:text="ABC Restoran Full Menu"
android:textSize="12pt"
android:shadowDx="0"
android:shadowDy="0"
android:shadowRadius="10"
android:layout_width="wrap_content"
android:layout_gravity="center"
></TextView>
<RelativeLayout
android:id="#+id/RelativeLayout02"
android:layout_height="fill_parent"
android:layout_width="fill_parent">
<ListView
android:layout_height="wrap_content"
android:id="#+id/ListView_ProfileMenu"
android:layout_width="fill_parent"
android:layout_alignParentTop="true"></ListView>
</RelativeLayout>
</LinearLayout>
menu_item.xml
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:textSize="10pt"
android:text="#string/hello"
android:layout_gravity="center_horizontal"
android:layout_height="wrap_content"
android:shadowRadius="5"
android:gravity="left"
android:textColor="#color/menulisting"
android:shadowDy="3"
android:shadowDx="3" />
ShowMenuActivity.java
public class ShowMenuActivity extends Activity {
DatabaseHandler db = new DatabaseHandler(this);
static String log = null;
public static String strProfileName;
public static int ID;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.viewmenu);
ListView profileList = (ListView) findViewById(R.id.ListView_ProfileMenu);
List<Contact> profiles = db.getAllContacts();
ArrayList<String> nameList = new ArrayList<String>();
for (Contact cn : profiles) {
strProfileName = cn.getmenuname() + " " + cn.getmenuprice();
nameList.add(strProfileName);
}
ArrayAdapter<String> adapt = new ArrayAdapter<String>(this, R.layout.menu_item, nameList);
profileList.setAdapter(adapt);
db.close();
}
}
following code will generate the layout you need
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/linearLayout2"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="#+id/itemCount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.50"
android:text=""
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/itemName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.50"
android:text=""
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
+1 list_item.xml and design the layout as you like.
see snippet below as an example for custom layout for list item;
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="#+id/rl_row"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#drawable/listitem_selector"
>
<LinearLayout android:id="#+id/lay_main"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#drawable/listitem_selector"
>
<LinearLayout android:id="#+id/lay_userProfile_userPicture"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="visible"
android:gravity="left"
android:layout_gravity="left"
android:orientation="vertical"
android:layout_marginLeft="#dimen/margin_size_medium"
>
<ImageView android:id="#+id/avatar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/profilepic"
android:background="#null"
/>
</LinearLayout>
<LinearLayout android:id="#+id/lay_details"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_gravity="center"
android:orientation="vertical"
android:layout_margin="#dimen/margin_size_medium"
>
<RelativeLayout android:id="#+id/lay_subdetails"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<TextView android:id="#+id/txt_mainTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/margin_size_medium"
android:layout_marginTop="#dimen/margin_size_small"
android:layout_alignParentLeft="true"
android:layout_alignBaseline="#+id/txt_dateTxt"
android:text="main txt"
android:textSize="#dimen/text_size_medium"
android:textStyle="bold"
android:textColor="#drawable/titlecolor"
android:singleLine="false"
/>
<TextView android:id="#+id/txt_dateTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="#dimen/margin_size_medium"
android:layout_marginTop="#dimen/margin_size_small"
android:layout_alignParentRight="true"
android:text="datetime txt"
android:textSize="#dimen/text_size_extrasmall"
android:textStyle="normal"
android:textColor="#drawable/normaltextcolor"
android:singleLine="false"
/>
</RelativeLayout>
<TextView android:id="#+id/txt_subTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/margin_size_medium"
android:singleLine="false"
android:text="subtxt"
android:textSize="#dimen/text_size_small"
android:textColor="#drawable/normaltextcolor"
android:layout_gravity="left"
/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
I would make a relative layout with two TextViews in it in my list_item xml and float one left and the other right.

how to use item click listner twice in a listview in android

i have a list view which shows 3 headings id , name and type and at last there is a line of checkbox what i want is
if i click value of 1st three heading it should be open in a drill down one more listview while when i check my checkbox which is at last only checkbox is checked no other action should take place
my code s here as below
sfreport.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:background="#EFEFF7"
android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:paddingLeft="2px"
android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal">
<TextView android:text="ID" android:width="80dip" android:layout_width="wrap_content"
android:layout_height="fill_parent" style="#style/hdrListing" android:height="25sp" />
<TextView android:text="Name" android:layout_weight="1.0" android:layout_width="wrap_content"
android:layout_height="fill_parent" style="#style/hdrListing" android:height="25sp" />
<TextView android:text="Type" android:width="80dip" android:layout_width="wrap_content"
android:layout_height="fill_parent" style="#style/hdrListing" android:height="25sp" />
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:paddingLeft="2px"
android:paddingRight="2px" android:background="#000000"
android:layout_width="fill_parent" android:layout_height="2px" android:orientation="horizontal">
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:paddingLeft="2px"
android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#EFEFF7">
<ListView xmlns:android="http://schemas.android.com/apk/res/android" android:id="#id/android:list"
android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#EFEFF7"
android:choiceMode="multipleChoice" />
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:gravity="bottom"
android:layout_height="fill_parent" android:layout_width="fill_parent" android:id="#+id/ll6" />
</LinearLayout>
while my other xml where i set the value is
<?xml version="1.0" encoding="utf-8"?>
<SRTekBox.Android.SRSD.widget.CheckableLinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:DRST="http://schemas.android.com/apk/res/SRTekBox.Android.SRSD" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:background="#color/list_bg">
<TextView android:id="#+id/itemID" android:width="80dip"
android:layout_centerVertical="true" android:textColor="#000000" android:focusable="false"
android:layout_width="wrap_content" android:layout_height="fill_parent" />
<TextView android:id="#+id/itemCaption" android:layout_weight="1.0"
android:layout_centerVertical="true" android:textColor="#000000" android:focusable="false"
android:layout_width="wrap_content" android:layout_height="fill_parent"/>
<TextView android:id="#+id/itemType" android:width="80dip" android:gravity="center"
android:layout_centerVertical="true" android:textColor="#000000" android:focusable="false"
android:layout_width="wrap_content" android:layout_height="fill_parent"/>
<SRTekBox.Android.SRSD.widget.InertCheckBox android:id="#+id/itemCheckBox"
android:layout_width="19dip" android:layout_height="fill_parent" android:focusable="false"
android:layout_centerVertical="true" android:button="#drawable/checkbox" android:width="19px" />
</SRTekBox.Android.SRSD.widget.CheckableLinearLayout>
this is my java code--->
/* public void onListItemClick(ListView parent,View v,int position,long id){
TextView t=(TextView)v.findViewById(R.id.itemID);
TextView t4=(TextView)v.findViewById(R.id.itemCaption);
TextView t5=(TextView)v.findViewById(R.id.itemType);
String sID="";
String sName="";
String SType="";
sID = t.getText().toString();
sName = t4.getText().toString();
SType=t5.getText().toString();
//v.setBackgroundColor(Color.rgb(119,136,153));
if("".equals(sID) || "MY VISIT SUMMARY".equals(sDesc)){
return;
}
if("0".equals(sName)){
return;
}
if("SA-E".equals(SType)){
Intent intent=new Intent(this,SRSDReportsDrillDown.class);
startActivity(intent);
}
}*/
public void onListItemClick(ListView parent,View v,int position,long id){
try{
if(listView.isItemChecked(position)){
int idx=position;
Integer listCount=listView.getCount();
for(Integer xx=0;xx<listCount;xx++){
if(idx==xx){
listView.setItemChecked(xx,true);
popup();
}
else{
}
return;
}
}
}
catch(Exception ex){
MsgBox1(this,ex.toString());
}
}

Categories

Resources