Im programming a app which shows meals with a picture,name and a short description. If pressed on one meal it should extend the size of the listitem to
get from this http://puu.sh/lmwKn/b5f6f1d54a.jpg to this http://puu.sh/lmwJo/943f7349d3.jpg.
Now to add meals to the ListView i wrote an MealAdapter, i dont know how to get the view of the list of the comments
#Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder viewHolder = null;
if (convertView == null) {
convertView = LayoutInflater.from(context).inflate(
R.layout.gericht_list_layout, null);
viewHolder = new ViewHolder();
viewHolder.img = (ImageView) convertView.findViewById(R.id.gericht_image);
viewHolder.name = (TextView) convertView.findViewById(R.id.gericht_title);
viewHolder.descTxt = (TextView) convertView.findViewById(R.id.gericht_sub_title);
viewHolder.comments = (ListView) convertView.findViewById(R.id.gericht_comments);
convertView.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) convertView.getTag();
}
viewHolder.name.setText(data.get(position).name);
viewHolder.descTxt.setText(data.get(position).subName);
int id = convertView.getResources().getIdentifier(
data.get(position).img, "drawable",
context.getPackageName());
viewHolder.img.setImageResource(id);
return convertView;
}
Here is the layout:
<?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">
<ImageView
android:id="#+id/gericht_image"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_alignParentLeft="true"
android:src="#drawable/no_image"
/>
<TextView
android:id="#+id/gericht_title"
android:layout_width="fill_parent"
android:layout_height="75dp"
android:layout_toRightOf="#+id/gericht_image"
android:text="Kein Name"
android:layout_marginLeft="15dp"
android:layout_marginTop="20dp"
android:textColor="#000000"
android:textSize="25sp"
/>
<TextView
android:id="#+id/gericht_sub_title"
android:layout_width="fill_parent"
android:layout_height="25dp"
android:text="Keine genauere Beschreibung"
android:layout_toRightOf="#+id/gericht_image"
android:layout_marginTop="55dp"
android:layout_marginLeft="30dp"
android:gravity="center_vertical"
/>
<ListView
android:id="#+id/gericht_comments"
android:layout_width="fill_parent"
android:layout_marginTop="100dp"
android:layout_marginLeft="50dp"
android:layout_height="0dp"
/>
</RelativeLayout>
So i want to draw the gericht_comments listview but i dont know how
Related
I'm currently struggling with a function I want to have in my application. The users Incomes are shown in a ListView. There are two types of incomes, normal "income" and "other income", this is selected in the application when the user submits the income to a SQLite Database that he or she receives. Now - I want to present the different incomes in a ListView with an image in the ListView relative to the type of category (two types of income category - "income" and "other income".
I cant figure out how I should do this ... can you do a switch-statement of some sort!?
My XML for the Custom ListView looks like this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="100">
<ImageView
android:orientation="vertical"
android:layout_width="48dp"
android:layout_height="48dp"
android:gravity="center_vertical"
android:id="#+id/icon1"/>
<LinearLayout
android:orientation="vertical"
android:layout_width="220dp"
android:layout_height="48dp"
android:layout_weight="33.3">
<TextView
android:text="TextView1"
android:textSize="18dp"
android:gravity="center_vertical"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:id="#+id/text1"/>
<TextView
android:text="Textview2"
android:textSize="14dp"
android:gravity="center_vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:="#id/text2"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="48dp"
android:orientation="vertical">
<TextView
android:text="Textview3"
android:textSize="16dp"
android:layout_width="wrap_content"
android:layout_height="48dp"
android:layout_gravity=""
android:gravity="center_vertical"
android:id="#+id/text3"/>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="48dp"
android:layout_height="48dp">
<ImageView
android:orientation="vertical"
android:layout_width="48dp"
android:layout_height="48dp"
android:gravity="center_vertical"
android:id="#+id/icon2"/>
</LinearLayout>
</LinearLayout>
And my AdapterClass looks like this:
public class CustomIncomeListAdapter extends ArrayAdapter<IncomeModel> {
private ArrayList<IncomeModel> incomeList;
private Activity context;
private ViewHolder viewHolder;
int[] incomeIcon = {R.drawable.income, R.drawable.otherincome};
int[] forwardIcon = {R.drawable.forward};
public CustomIncomeListAdapter(Activity context, int[] incomeIcon, ArrayList<IncomeModel> incomeList) {
super(context, R.layout.adapter_view_layout, incomeList);
this.incomeList = incomeList;
this.context = context;
this.incomeIcon = incomeIcon;
}
private static class ViewHolder {
TextView incomeReference;
TextView incomeDate;
TextView incomeAmount;
ImageView incomeIcon;
ImageView forwardIcon;
}
public View getView(int position, View convertView, ViewGroup parent) {
IncomeModel incomeModel = getItem(position);
if (convertView == null) {
viewHolder = new ViewHolder();
LayoutInflater inflater = context.getLayoutInflater();
convertView = inflater.inflate(R.layout.adapter_view_layout, null, true);
viewHolder.incomeReference = (TextView) convertView.findViewById(R.id.text1);
viewHolder.incomeDate = (TextView) convertView.findViewById(R.id.text2);
viewHolder.incomeAmount = (TextView) convertView.findViewById(R.id.text3);
viewHolder.incomeIcon = (ImageView) convertView.findViewById(R.id.icon1);
viewHolder.forwardIcon = (ImageView) convertView.findViewById(R.id.icon2);
convertView.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) convertView.getTag();
}
viewHolder.incomeReference.setText(incomeModel.getIncomeCategory());
viewHolder.incomeDate.setText(incomeModel.getIncomeDate());
viewHolder.incomeAmount.setText(incomeModel.getIncomeAmount());
switch (...?) {
}
}
viewHolder.incomeAmount.setText(incomeModel.getIncomeAmount());
switch (income) {
//define your income to 1 for other income
case 1:
incomeIcon.setBackgroundResource(R.drawable.otherincome);
break;
default:
incomeIcon.setBackgroundResource(R.drawable.income);
break;
}
you can check type , if type is income means set corresponding image else set other image
I currently have an expandable list view that is populating just fine. However when the child view is filling it creates individuals views and rows for each entry. I would like to have one view and multiple textviews in the view as well as a button that I will be adding. The data is being populated from a HASHMAP. I have tried many things and cannot get multiple textviews to populate correctly in the listview.
All data comes from this hashmap:
private HashMap<String, List<String>> _deviceDetails;
This is the get child view method of my custom adapter.
#Override
public View getChildView(int groupPosition, final int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
final String childText = (String) getChild(groupPosition, childPosition);
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) this._context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.list_item, null);
}
TextView txtListChild = (TextView) convertView
.findViewById(R.id.lblListItem);
txtListChild.setText(childText);
return convertView;
}
This is an image of what I have now with what I wish to do.
I need the data highlighted inside of one row so that I can add buttons etc without a bunch of rows. I genuinely cannot figure out how to do this properly.
I'm an idiot. I figured it out. Thank you #Krupal you pointed me in the right direction. If you place anything as an answer i'll select you because you got me thinking the right way.
So what I ended up doing here was I created a custom List Adapter. I won't add the entire class to keep it short. The key was to use set the adapter to only return one child. Then in the child that was returned (XML below) I had all of my needed fields added in. So now when I expanded the list only one child would be visible. Also in my getChildView() I defined all needed entries for the layout for the children. Don't know if this is the perfect way to do it but worked nicely for my needs.
This is where I actually configured the child with my data.
#Override
public View getChildView(int groupPosition, final int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
final String childText = (String) getChild(groupPosition, 0);
final String childTextSecond = (String) getChild(groupPosition, 1);
final String childTextThird = (String) getChild(groupPosition, 2);
final String deviceName = (String) getChild(groupPosition, 3);
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) this._context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.list_item, null);
}
TextView txtListChild = (TextView) convertView
.findViewById(R.id.lblListItem);
TextView txtListChildTwo = (TextView) convertView
.findViewById(R.id.lblListItemTwo);
TextView txtListChildThree = (TextView) convertView
.findViewById(R.id.lblListItemThree);
//rest of logic!
}
Setting the children count to 1
#Override
public int getChildrenCount(int groupPosition) {
return 1;
}
XML Layout for the child elements
<?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"
android:background="#000000">
<RelativeLayout
android:layout_width="340dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|right"
android:background="#f9fcff">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_centerHorizontal="true"
android:layout_alignParentTop="true"
android:background="#4d86ff">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_gravity="center_horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="#android:style/TextAppearance.Medium"
android:layout_marginLeft="10dp"
android:text="Large Text"
android:id="#+id/lblListItem"
android:textColor="#ffffff"
android:layout_alignTop="#+id/textView5"
android:layout_toRightOf="#+id/textView5"
android:layout_toEndOf="#+id/textView5" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:textAppearance="#android:style/TextAppearance.Medium"
android:text="Device ID: "
android:id="#+id/textView5"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:textColor="#ffffff" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:text="Tags"
android:id="#+id/btnTags"
android:background="#ffffff"
android:singleLine="true"
android:layout_alignTop="#+id/lblListItem"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginRight="15dp"
android:layout_marginEnd="15dp" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_gravity="center_horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:textAppearance="#android:style/TextAppearance.Medium"
android:text="Status: "
android:id="#+id/textView6"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:textColor="#ffffff" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:textAppearance="#android:style/TextAppearance.Medium"
android:text="Large Text"
android:id="#+id/lblListItemTwo"
android:textColor="#ffffff"
android:layout_alignTop="#+id/textView6"
android:layout_toRightOf="#+id/textView6"
android:layout_toEndOf="#+id/textView6" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginBottom="10dp"
android:textColor="#ffffff"
android:textAppearance="#android:style/TextAppearance.Medium"
android:text="Description: "
android:id="#+id/textView7"
android:layout_marginStart="15dp"
android:layout_alignTop="#+id/lblListItemThree"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="6dp"
android:layout_marginRight="13dp"
android:layout_marginBottom="10dp"
android:textAppearance="#android:style/TextAppearance.Medium"
android:text="Large Text"
android:id="#+id/lblListItemThree"
android:textColor="#ffffff"
android:layout_marginStart="39dp"
android:layout_alignParentTop="true"
android:layout_toRightOf="#+id/textView7"
android:layout_toEndOf="#+id/textView7" />
</RelativeLayout>
</LinearLayout>
</RelativeLayout>
VisiIn my custom adapter getView method, I have a switch case for different types of layout cells. I refer to one layout xml for these cells and show/hide certain elements by setVisibility(View....) In my first cell, "StreamLayout," all I want to show is one imageView, "Boombox". I set this image view as invisible in all the other layouts, but when I do this, it won't show up in the first one. I will provide my getView method and my layout xml:
getView:
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
holder = null;
int type = getItemViewType(position);
if (convertView == null) {
convertView = mInflater.inflate(R.layout.listview_cell, null);
holder = new ViewHolder();
} else {
holder = (ViewHolder) convertView.getTag();
}
switch (type) {
case STREAM_LAYOUT:
convertView = mInflater.inflate(R.layout.listview_cell, null);
ImageView boombox = (ImageView) convertView.findViewById(R.id.boombox).setVisibility(View.Visible);
convertView.findViewById(R.id.cell_image).setVisibility(View.GONE);
convertView.findViewById(R.id.divider).setVisibility(View.GONE);
convertView.findViewById(R.id.song).setVisibility(View.GONE);
convertView.findViewById(R.id.artist).setVisibility(View.GONE);
convertView.findViewById(R.id.bottom_layout).setVisibility(View.GONE);
convertView.setTag(holder);
case TALKSET_LAYOUT:
convertView.findViewById(R.id.boombox).setVisibility(View.GONE);
convertView.findViewById(R.id.cell_image).setVisibility(View.GONE);
convertView.findViewById(R.id.divider).setVisibility(View.GONE);
convertView.findViewById(R.id.playcut).setVisibility(View.GONE);
holder.talkset = (TextView) convertView.findViewById(R.id.talk_break_text);
holder.talkset.setText("TALKSET");
holder.talkset_icon = (ImageView) convertView.findViewById(R.id.talk_break_image);
holder.talkset_icon.setImageResource(R.drawable.temp_talkset);
convertView.setTag(holder);
break;
case BREAKPOINT_LAYOUT:
convertView.findViewById(R.id.boombox).setVisibility(View.GONE);
convertView.findViewById(R.id.cell_image).setVisibility(View.GONE);
convertView.findViewById(R.id.divider).setVisibility(View.GONE);
convertView.findViewById(R.id.artist).setVisibility(View.GONE);
//convertView.findViewById(R.id.boombox).setVisibility(View.GONE);
long l = Long.parseLong(oslist.get(position).get("hour"));
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(l);
calendar.setTimeInMillis(l * 1000);
int hour = calendar.get(Calendar.HOUR);
holder.song.setText("Breakpoint: "+hour+":00");
holder.breakpoint = (TextView) convertView.findViewById(R.id.talk_break_text);
holder.breakpoint.setText("BREAKPOINT");
holder.breakpoint_icon = (ImageView) convertView.findViewById(R.id.talk_break_image);
holder.breakpoint_icon.setImageResource(R.drawable.temp_talkset);
convertView.setTag(holder);
break;
case PLAYCUT_LAYOUT: //Playcut
convertView = mInflater.inflate(R.layout.listview_cell, null);
convertView.findViewById(R.id.boombox).setVisibility(View.GONE);
holder.cell_image = (ImageView) convertView.findViewById(R.id.cell_image);
try {
if(oslist.get(position).get("albumArtUrl")!=null) {
Picasso
.with(context)
.load(oslist.get(position).get("albumArtUrl"))
.placeholder(R.drawable.no_album_art)
.error(R.drawable.no_album_art).into(holder.cell_image);
}else{
Picasso
.with(context)
.load(oslist.get(position).get("artistArtUrl"))
.placeholder(R.drawable.no_album_art)
.error(R.drawable.no_album_art).into(holder.cell_image);
}
} catch (IllegalArgumentException e) {
holder.cell_image.setImageResource(R.drawable.no_album_art);
}
holder.song = (TextView) convertView.findViewById(R.id.song);
holder.artist = (TextView) convertView.findViewById(R.id.artist);
holder.song.setText(oslist.get(position).get("songTitle"));
holder.artist.setText(oslist.get(position).get("artistName"));
convertView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
updateView(position);
}
});
convertView.setTag(holder);
break;
case NULL_LAYOUT:
convertView.setTag(holder);
break;
}
return convertView;
}
MY XML
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:src="#drawable/boombox"
android:id="#+id/boombox"
/>
<!-- Versatile image view storage for either boombox, no album art image, or album art -->
<ImageView
android:id="#+id/cell_image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
/>
<!-- Divider between image and data -->
<View
android:id="#+id/divider"
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#android:color/darker_gray"/>
<!-- Layout for bottom half of playcut cells -->
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/bottom_layout"
android:layout_below="#id/divider">
<!-- Data for Song and Artist -->
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/playcut">
<TextView
android:id="#+id/song"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textStyle="bold"
android:gravity="center"
/>
<TextView
android:id="#+id/artist"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/song"
android:gravity="center"
/>
</RelativeLayout>
<!-- Talkset and breakpoint cell data -->
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/talk_break"
android:paddingLeft="1dp"
android:paddingTop="1dp"
android:paddingBottom="1dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/talk_break_image"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/talk_break_text"
android:layout_toRightOf="#id/talk_break_image"/>
</RelativeLayout>
<!-- Playcut Cell, clicked, displaying Facebook, Twitter, heart, and search icons -->
<TableLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="0,1,2,3,4"
android:paddingBottom="2dp"
android:id="#+id/table">
<TableRow>
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/twitter_icon"/>
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/facebook_icon"/>
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/unclicked_heart_icon"/>
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/search_icon"/>
</TableRow>
</TableLayout>
</RelativeLayout>
</LinearLayout>
The reason this doesn't work is because you're using a ViewHolder which will maintain a reference to each UI element for all adapter items.
Because of this, if an element is set to View.GONE in the first iteration and isn't touched again, it will remain in that state, regardless of how it is defined in the XML.
To work around this, you should always explicitly set the visibility of that element in getView() depending on which layout you are using, because if it is anything but the first iteration you will be referencing the ViewHolder and the state it is in, not the view inflated by the XML file.
i am a beginer android-developer and i need some help:
There is a Fragment in my Project - TasksFragment, there is a ListView element on it. On ListView, using ArrayAdapter Items are formed by a custom layout for Item and then added to ListView. The problem is, that ListView don't react on click processing events.
Here are the code fragments:
TaskAdapter class...
public class TaskAdapter extends ArrayAdapter<Task> {
public TaskAdapter(ArrayList<Task> tasks) {
super(getActivity(), 0, tasks);
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = getActivity().getLayoutInflater().inflate(R.layout.list_item_task, null);
}
Task task = getItem(position);
TextView titleTextView = (TextView) convertView.findViewById(R.id.task_list_item_titleTextView);
titleTextView.setText(task.getTitle());
CheckBox solvedCheckBox = (CheckBox) convertView.findViewById(R.id.task_list_item_solvedCheckBox);
solvedCheckBox.setChecked(task.isSolved());
return convertView;
}
}
ItemClick fragment.
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.tasks_fragment, null);
mTasks = TaskLab.get(getActivity()).getTasks();
final ListView lvMain = (ListView) view.findViewById(R.id.listViewTasks);
lvMain.setClickable(true);
TaskAdapter adapter = new TaskAdapter(mTasks);
setHasOptionsMenu(true);
lvMain.setAdapter(adapter);
lvMain.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Task task = (Task)lvMain.getItemAtPosition(position);
Toast.makeText(getActivity().getApplicationContext(), task.getTitle() + " was clicked", Toast.LENGTH_LONG).show();
Intent i = new Intent(getActivity(), AddTaskActivity.class);
startActivity(i);
}
});
return view;
}
XML Layout for List_Item_Task
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<CheckBox
android:id="#+id/task_list_item_solvedCheckBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_alignParentRight="true"
android:enabled="false"
android:padding="4dp"/>
<TextView
android:id="#+id/task_list_item_titleTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toLeftOf="#+id/task_list_item_solvedCheckBox"
android:textStyle="bold"
android:paddingLeft="4dp"
android:paddingRight="4dp"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:textSize="22dp"/>
</RelativeLayout>
Xml layout for tasks_fragment.xml
<?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"
android:background="#3f638b">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textViewTasksFragmentHeader"
android:text="Задачи"
android:textSize="30dp"
android:layout_gravity="center_horizontal"
android:layout_centerHorizontal="true"/>
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/listViewTasks" />
</LinearLayout>
Yes your listview is not clickable.
Just add this in your checkbox layout
android:focusable="false"
Your items xml should look like this
<?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" >
<CheckBox
android:id="#+id/task_list_item_solvedCheckBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="false" //Add this
android:layout_alignParentRight="true"
android:gravity="center"
android:padding="4dp" />
<TextView
android:id="#+id/task_list_item_titleTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toLeftOf="#+id/task_list_item_solvedCheckBox"
android:paddingBottom="5dp"
android:paddingLeft="4dp"
android:paddingRight="4dp"
android:paddingTop="5dp"
android:textSize="22dp"
android:textStyle="bold" />
Now it should work. I have tested it :)
I have a listview and inside it is a texview. Sometimes only the first character is displayed. And when I refresh the view, the whole word appears. Has anyone experience this? How do I fix this bug? Thanks in advance
Here is my code:
ListView tasksList = (ListView) findViewById(R.id.tasks_list);
tasksListAdapter = new SimpleAdapter(this, tasksListItems, R.layout.advanced_view_row,
new String[] {LIST_ADAPTER_APPLICATION_ICON, LIST_ADAPTER_KEY_NAME, LIST_ADAPTER_KEY_RECEIVED, LIST_ADAPTER_KEY_SENT},
new int[] {R.id.application_icon, R.id.process_name, R.id.received, R.id.sent}
)
{
#Override
#SuppressWarnings("unchecked")
public View getView(int position, View convertView, ViewGroup parent)
{
if (convertView == null)
{
convertView = LayoutInflater.from(parent.getContext()).
inflate(R.layout.advanced_view_row, parent, false);
}
HashMap<String, Object> item = (HashMap<String, Object>)this.getItem(position);
((ImageView) convertView.findViewById(R.id.application_icon)).setImageDrawable((Drawable) item.get(LIST_ADAPTER_APPLICATION_ICON));
((TextView) convertView.findViewById(R.id.process_name)).setText((String) item.get(LIST_ADAPTER_KEY_NAME));
((TextView) convertView.findViewById(R.id.received)).setText((String) item.get(LIST_ADAPTER_KEY_RECEIVED));
((TextView) convertView.findViewById(R.id.sent)).setText((String) item.get(LIST_ADAPTER_KEY_SENT));
return convertView;
};
};
tasksList.setAdapter(tasksListAdapter);
<?xml version="1.0" encoding="utf-8"?>
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:paddingTop="5dip"
android:paddingBottom="5dip"
android:layout_height="fill_parent"
android:layout_width="fill_parent">
<TableRow>
<TextView
android:id="#+id/status"
android:layout_height="fill_parent"
android:layout_width="0dip"
android:layout_weight="0.01"/>
<ImageView
android:id="#+id/application_icon"
android:layout_width="32dip"
android:layout_height="32dip"
android:layout_weight="0.09"/>
<TextView
android:id="#+id/process_name"
android:layout_height="wrap_content"
android:layout_width="0dip"
android:layout_weight="0.4"/>
<TextView
android:id="#+id/received"
android:layout_height="wrap_content"
android:layout_width="0dip"
android:layout_weight="0.25"
android:gravity="right"/>
<TextView
android:id="#+id/sent"
android:layout_height="wrap_content"
android:layout_width="0dip"
android:layout_weight="0.25"
android:gravity="right"/>
</TableRow>
</TableLayout>
Change layout_width of TextView with id=application_icon to 0dip (instead of 32dip).
In which TextView you have only one character displayed?