I am working on an application which contains Custom ListView on its main activity. It was working fine but the day before yesterday, list view items are suddenly become non-clickable. I've searched a lot, but no answer solved my this issue. It is strange. Normal list view is working good, but custom isn't. What may be the problem?
Edit: Custom List View is as normal as it is, nothing odd. I am giving here CustomAdapter class.
#Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null){
LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.custom_list, null);
}
ClassDetailPedia detailPedia = personDetail.get(position);
if(detailPedia !=null){
TextView txtPersonName = (TextView) convertView.findViewById(R.id.txtPersonName);
TextView txtReason = (TextView) convertView.findViewById(R.id.txtReason);
TextView txtTags = (TextView) convertView.findViewById(R.id.txtTags);
TextView txtDate = (TextView) convertView.findViewById(R.id.txtDate);
ImageView imgPerson = (ImageView) convertView.findViewById(R.id.imgPerson);
txtPersonName.setText(detailPedia.getTitle());
txtReason.setText("Description: " + detailPedia.getDescription());
txtTags.setText("Tags: " + detailPedia.getTags());
txtDate.setText(GetFormattedDate(detailPedia.getDated()));
if(detailPedia.getImage() != null) {
imgPerson.setImageURI(detailPedia.getImage());
imgPerson.setScaleType(ImageView.ScaleType.CENTER);
}
}
return convertView;
}
and it extends ArrayAdapter<ClassDetailPedia>
And here I am setting CustomAdapter
ListView lstPersons = (ListView) findViewById(R.id.lstDetail);
lstPersons.setAdapter(new CustomAdapter(getApplicationContext(), R.layout.custom_list, pediaList));
custom_list.xml
<?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="wrap_content"
android:background="#drawable/shape_list"
android:gravity="center">
<ImageButton
android:layout_width="80dp"
android:layout_height="60dp"
android:src="#drawable/empty_picture"
android:id="#+id/imgPerson"
android:scaleType="centerCrop" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginTop="2dp">
<TextView
android:textColor="#000000"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Friday, April 1, 2016 # 8:30pm"
android:id="#+id/txtDate"
android:textStyle="italic"
android:textSize="12sp"
android:layout_below="#+id/txtTags"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginTop="3dp"
android:layout_marginRight="3dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000000"
android:text="Mr. Bill Gates"
android:id="#+id/txtPersonName"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:layout_marginStart="3dp"
android:singleLine="true"
android:textSize="17sp"
android:layout_marginBottom="3dp"
android:textStyle="bold"/>
<TextView
android:textColor="#000000"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Reason: Marketing Strategy"
android:id="#+id/txtReason"
android:layout_below="#+id/txtPersonName"
android:layout_alignParentStart="true"
android:layout_marginStart="3dp"
android:singleLine="true"
android:layout_marginTop="-3dp"
android:textSize="13sp"/>
<TextView
android:textColor="#000000"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="tags: business, start-up"
android:id="#+id/txtTags"
android:layout_below="#+id/txtReason"
android:layout_alignParentStart="true"
android:layout_marginStart="3dp"
android:singleLine="true"
android:textSize="13sp"/>
</RelativeLayout>
</LinearLayout>
Try add android:descendantFocusability="blocksDescendants" for the root view of your custom list item (in your case it is LinearLayout)
<?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="wrap_content"
android:background="#drawable/shape_list"
android:gravity="center"
android:descendantFocusability="blocksDescendants"
>
...
</LinearLayout>
I made new Application, copied and pasted all the files and code and it's working fine. I don't know what caused the problem and why it is working perfectly know.
Related
I have created a custom ListView with 2 ImageView and a TextView.
In the Adapter, I'm doing setText in TextView, but it is not visible in the app.
Here is my List:
<?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="#ffffff">
<View
android:layout_width="fill_parent"
android:layout_height="5dp"
android:background="#289FA5"/>
<RelativeLayout
android:layout_marginTop="7dp"
android:layout_marginLeft="7dp"
android:layout_marginBottom="15dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#289FA5">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Popular products"
android:textSize="23sp"
android:padding="7dp"/>
</RelativeLayout>
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="120dp">
<LinearLayout
android:id="#+id/pop_pro_men"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
</LinearLayout>
</HorizontalScrollView>
<RelativeLayout
android:layout_marginTop="15dp"
android:layout_marginLeft="7dp"
android:layout_marginBottom="15dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#289FA5">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Catagories"
android:textSize="23sp"
android:padding="7dp"/>
</RelativeLayout>
<ListView
android:id="#+id/cata_men"
android:layout_width="fill_parent"
android:layout_height="wrap_content"></ListView>
Here is my Custom List:
<LinearLayout
android:id="#+id/custom_list"
android:layout_width="match_parent"
android:layout_height="130dp"
android:layout_marginTop="10dp"
android:orientation="horizontal"
android:background="#ffffff">
<ImageView
android:layout_gravity="left"
android:id="#+id/imageView2"
android:layout_height="130dp"
android:layout_marginLeft="7dp"
android:layout_width="120dp"
android:src="#drawable/clothing_men"/>
<TextView
android:id="#+id/cata_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Clothing"
android:layout_marginTop="35dp"
android:textStyle="bold"
android:textSize="27sp"
android:padding="10dp"
android:layout_weight="1"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/forward_arrow"
android:layout_marginTop="42dp"/>
And Here is the getView method of my Adapter:
public View getView(final int position, View convertView, ViewGroup parent) {
final Holder holder = new Holder();
View rowView;
rowView = inflater.inflate(R.layout.custom_subcatagory_list, null,true);
TextView sub_catagory= (TextView) rowView.findViewById(R.id.cata_name);
ImageView pic = (ImageView) rowView.findViewById(R.id.imageView2);
sub_catagory.setText(catagory[position]);
pic.setImageResource(image[position]);
Log.d("Strings========", sub_catagory.getText().toString());
rowView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Toast.makeText(context, "You Clicked " + catagory[position], Toast.LENGTH_LONG).show();
}
});
return rowView;
}
Please Help as i am unable to find what is wrong in this.
Remove your layout_weight attribute from your TextView. If you remove sub_catagory.setText(catagory[position]); does "Clothing" appear when you run your app?
I got the answer now. I don't know how my textColor was set to White, because i didn't mentioned it. So, change the color to something else and it worked.And it wasted my whole day.
Sorry to disturb you all.
I have spent so much time searching for solutions and tried different ways but couldn't find where it goes wrong.
I am developing an app where I have an ImageButton as child element of a listView (I have done this using Custom Adapters). Upon executing OnClick of the ImageButton, nothing happens.
My fragment_tweets.xml looks as follows:
<?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.support.v4.widget.SwipeRefreshLayout android:id="#+id/swipeContainer"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/lvTweets" />
</android.support.v4.widget.SwipeRefreshLayout>
</LinearLayout>
item_tweet.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:descendantFocusability="blocksDescendants"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false"
>
<ImageButton
android:layout_width="#dimen/profile_image_view_length"
android:layout_height="#dimen/profile_image_view_length"
android:background="#android:color/transparent"
android:id="#+id/ivProfilePicture"
android:scaleType="centerCrop"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:focusable="false"
android:focusableInTouchMode="false"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/tvUserName"
android:textColor="#color/black"
android:layout_alignTop="#+id/ivProfilePicture"
android:layout_toRightOf="#+id/ivProfilePicture"
android:layout_marginBottom="#dimen/margin_10dp"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false"
android:textIsSelectable="false"/>
<com.codepath.apps.twitterclient.helpers.LinkifiedTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/tvBody"
android:textColor="#color/black"
android:layout_toRightOf="#+id/ivProfilePicture"
android:autoLink="all"
android:layout_marginTop="#dimen/margin_30dp"
android:layout_marginBottom="#dimen/margin_10dp"
android:focusable="false"
android:focusableInTouchMode="false"
android:textIsSelectable="false"/>
/>
<ImageView
android:layout_width="#dimen/margin_10dp"
android:layout_height="#dimen/margin_10dp"
android:id="#+id/ivClock"
android:layout_toLeftOf="#+id/tvTimeofPost"
android:src="#mipmap/ic_clock"
android:layout_marginTop="#dimen/margin_15dp"
android:layout_marginBottom="#dimen/margin_10dp"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/tvTimeofPost"
android:textColor="#color/gray"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_marginTop="#dimen/margin_10dp"
android:layout_marginRight="#dimen/margin_5dp"
android:layout_marginLeft="#dimen/margin_5dp"
android:layout_marginBottom="#dimen/margin_10dp"
android:textIsSelectable="false"
android:focusable="false"
android:focusableInTouchMode="false"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/ivPostImage"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
android:layout_below="#+id/tvBody"
android:layout_alignLeft="#+id/tvBody"
android:layout_alignStart="#+id/tvBody"
android:layout_alignRight="#+id/tvTimeofPost"
android:layout_alignEnd="#id/tvTimeofPost"
android:layout_marginBottom="#dimen/margin_10dp"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false"/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/ivPostImage"
android:layout_alignLeft="#+id/ivPostImage"
android:layout_alignStart="#+id/ivPostImage"
android:layout_alignRight="#+id/ivPostImage"
android:layout_alignEnd="#id/ivPostImage"
android:weightSum="3">
<TextView android:id="#+id/tvReply"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/gray" android:layout_weight="1"
android:drawableLeft="#drawable/reply_small" android:layout_below="#+id/ivPostImage"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false"/>
<TextView
android:id="#+id/tvRetweetCount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:textColor="#color/gray"
android:drawableLeft="#drawable/retweet_small"
android:layout_weight="1"
android:drawablePadding=".5dp"
android:layout_centerVertical="true"
android:textSize="#dimen/text_size_13sp" android:layout_below="#+id/ivPostImage"
android:layout_alignRight="#+id/tvReply"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false"/>
<TextView
android:id="#+id/tvFavoriteCount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:textColor="#color/gray"
android:layout_weight="1"
android:drawableLeft="#drawable/favorite_small"
android:drawablePadding=".5dp"
android:textSize="#dimen/text_size_13sp"
android:layout_below="#+id/ivPostImage"
android:layout_alignRight="#+id/tvRetweetCount"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false"/>
</LinearLayout>
</RelativeLayout>
getView() of Adapter looks like this:
#Override
public View getView(int position, View convertView, ViewGroup parent) {
final Tweet tweet = getItem(position);
final ViewHolder viewHolder;
// If it's a retweeted tweet, display the original
if (tweet.getRetweeted() != null) {
tweetToDisplay = tweet.getRetweetedStatus();
} else {
tweetToDisplay = tweet;
}
if(convertView==null){
viewHolder = new ViewHolder();
LayoutInflater inflator = (LayoutInflater) getContext()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflator.inflate(R.layout.item_tweet, null);
convertView.setClickable(true);
convertView.setFocusable(true);
viewHolder.ivProfilePicture = (ImageButton) convertView.findViewById(R.id.ivProfilePicture);
}else{
viewHolder = (ViewHolder) convertView.getTag();
}
viewHolder.ivProfilePicture.setImageResource(0); // clear out the old image
// For Rounded image in profile picture
Transformation transformation = new RoundedTransformationBuilder()
.borderColor(Color.BLACK)
.borderWidthDp(1)
.cornerRadiusDp(30)
.oval(false)
.build();
Picasso.with(getContext()).load(tweet.getUser().getProfileImageUrl())
.transform(transformation)
.placeholder(R.mipmap.ic_launcher)
.into(viewHolder.ivProfilePicture);
Log.v("Tweets Adapter","Before onclick of profile pic");
viewHolder.ivProfilePicture.setTag(tweet.getUser().getScreenName());
viewHolder.ivProfilePicture.setFocusable(false);
viewHolder.ivProfilePicture.setFocusableInTouchMode(false);
viewHolder.ivProfilePicture.setClickable(true);
// View listener for showing the profile of user
viewHolder.ivProfilePicture.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Log.v("Adapter ", "inside onclick method");
// Launch the profile activity directly from the fragment
listener.profileClicked(tweet.getUser());
}
});
return convertView;
}
I have already tried various solutions posted.. Any help would be great.. Thanks in advance..
In your else statement use this:
viewHolder = (ViewHolder) convertView.getTag();
convertView.setClickable(true);
convertView.setFocusable(true);
Your convertview is focusable and clickable when is drawing but not when is redrawing.
Sorry for the bad title.
I am adding a toggle button at run-time to the list view.
When I click on the button its state gets changed. But the problem is that when I scroll down other items get selected too.
For example, if click on first toggle button the 6th toggle button gets checked too.
This is a very weird behavior.
Here is the XML code for the acitivty
<?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"
android:orientation="vertical">
<RelativeLayout
android:id="#+id/title_bar"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#color/eros_now_title_bar">
<ImageView
android:id="#+id/back_button_image"
android:layout_width="#dimen/toolbar_imageview_width_height"
android:layout_height="#dimen/toolbar_imageview_width_height"
android:layout_centerVertical="true"
android:layout_margin="#dimen/back_image_margin"
android:src="#drawable/ic_arrow_back" />
<ImageButton
android:id="#+id/back_button"
android:layout_width="#dimen/toolbar_imagebutton_width_height"
android:layout_height="#dimen/toolbar_imagebutton_width_height"
android:layout_centerVertical="true"
android:layout_marginRight="20dp"
android:background="#drawable/npd_back_feedback" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/back_button_image"
android:layout_toRightOf="#+id/back_button"
android:fontFamily="sans-serif-regular"
android:text="Invite friends"
android:textColor="#color/white"
android:textSize="18sp"
android:textStyle="bold" />
</RelativeLayout>
<EditText
android:id="#+id/search_text"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_below="#+id/title_bar"
android:layout_margin="15dp"
android:hint="Search"
android:textColorHint="#color/hint_color"
android:drawableRight="#drawable/search_blue_white"/>
<ListView
android:id="#+id/friends_list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/search_text"
android:layout_above="#+id/invite_count_view"
android:layout_marginTop="15dp"
android:divider="#color/transparent">
</ListView>
<RelativeLayout
android:id="#+id/invite_count_view"
android:layout_width="match_parent"
android:layout_height="56dp"
android:layout_alignParentBottom="true">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-light"
android:textSize="18sp"
android:textColor="#color/eros_now_title_bar"
android:text="10 more invites to go"
android:layout_centerInParent="true"
/>
</RelativeLayout>
</RelativeLayout>
Here is the XML code for the view I am inflating in the adapter
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/card_view"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="10dp"
android:paddingBottom="10dp">
<com.makeramen.roundedimageview.RoundedImageView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/person_pic"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_marginLeft="26dp"
android:layout_centerVertical="true"
app:riv_corner_radius="50dip"
android:src="#drawable/ic_person_grey600_36dp"/>
<TextView
android:id="#+id/name"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:singleLine="true"
android:layout_toRightOf="#+id/person_pic"
android:layout_marginLeft="17dp"
android:layout_centerVertical="true"
android:textColor="#color/black"
android:fontFamily="sans-serif-regular"
android:textSize="16sp"
android:text="Grumpy brother"
android:ellipsize="end"/>
<!--<ToggleButton-->
<!--android:layout_width="wrap_content"-->
<!--android:layout_height="wrap_content"-->
<!--android:layout_alignParentRight="true"-->
<!--android:layout_marginRight="35dp"-->
<!--android:layout_centerVertical="true"-->
<!--android:background="#drawable/invite_selector"-->
<!--android:textOn=""-->
<!--android:textOff=""-->
<!--android:text="" />-->
</RelativeLayout>
here is the code for getView
public View getView(int i, View convertView, ViewGroup parent) {
Log.e("getView", "name = " + contacts.get(i).getName());
if (convertView == null) {
convertView = LayoutInflater.from(activity).inflate(R.layout.friend_view, parent, false);
}
TextView name = (TextView) convertView.findViewById(R.id.name);
RoundedImageView image = (RoundedImageView) convertView.findViewById(R.id.person_pic);
ToggleButton selector = new ToggleButton(activity);
if (sdk < android.os.Build.VERSION_CODES.JELLY_BEAN)
selector.setBackgroundDrawable(activity.getResources().getDrawable(R.drawable.ic_add_black_24dp));
else
selector.setBackground(activity.getResources().getDrawable(R.drawable.ic_add_black_24dp));
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE);
params.addRule(RelativeLayout.ALIGN_PARENT_END, RelativeLayout.TRUE);
params.setMargins(0, 0, getPx(35), 0);
selector.setLayoutParams(params);
selector.setTextOff("");
selector.setText("");
selector.setTextOn("");
selector.setOnCheckedChangeListener(this);
selector.setTag(String.valueOf(i));
selector.setChecked(contacts.get(i).getSelectedState());
contacts.get(i).setButton(selector);
RelativeLayout card = (RelativeLayout) convertView.findViewById(R.id.card_view);
card.addView(selector);
try {
Bitmap bitmap = MediaStore.Images.Media.getBitmap(activity.getContentResolver(), contacts.get(i).getURI());
} catch (IOException e) {
contacts.get(i).setURI(Uri.parse(""));
}
name.setText(contacts.get(i).getName());
if (!contacts.get(i).getURI().toString().equals(""))
image.setImageURI(contacts.get(i).getURI());
else
image.setImageDrawable(activity.getResources().getDrawable(R.drawable.ic_person));
return convertView;
}
I saw that you used contacts.get(i).getSelectedState() to set ToggleButton state in getview.
Did you use Adapter.notifyDatasetChanged() to update the listview's state?
If not, add that code after toggle the button.
Because your item view is reused so only create ToggleButton if convertView is null. If convertView is not null, get it from convertView and set it's properties.
Use setTag and findViewWithTag to identity your ToggleButton.
I have a list view and an adapter. My problem is that the rows in the list are always "wrap content" even though I specifically stated the height as "150dp".
This is my adapter:
private class LiveEventsAdapter extends BaseAdapter {
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View contentView = convertView;
if (contentView == null) {
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
contentView = inflater.inflate(R.layout.live_match_row, null);
TypefaceManager.getInstance(LiveMatchActivity.this).assignTypeface(contentView);
}
if (events != null) {
Event event = events.getEventsList().get(position);
TypefaceManager typefaceManager = TypefaceManager.getInstance(LiveMatchActivity.this);
TextView eventText;
TextView minute;
ImageView eventIcon;
minute = (TextView) contentView.findViewById(R.id.live_match_minute);
if (event.getOrientation().equals("home")) {
eventText = (TextView) contentView.findViewById(R.id.home_team_event_text);
eventIcon = (ImageView) contentView.findViewById(R.id.home_team_event_img);
} else {
eventText = (TextView) contentView.findViewById(R.id.away_team_event_text);
eventIcon = (ImageView) contentView.findViewById(R.id.away_team_event_img);
}
minute.setText(event.getMinute() + "\'");
eventText.setText(event.getDescription());
minute.setTypeface(typefaceManager.getTypeface("bold"));
eventText.setTypeface(typefaceManager.getTypeface("bold"));
}
}
That's how I "setadapter":
ListView eventsListView = (ListView) findViewById(R.id.live_match_list);
eventsListView.setAdapter(new LiveEventsAdapter());
and that's my rows 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="150dp"
android:background="#drawable/background_button" >
<TextView
android:id="#+id/live_match_minute"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="82'" />
<TextView
android:id="#+id/home_team_event_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="false"
android:layout_alignRight="#+id/home_team_event_img"
android:layout_centerVertical="true"
android:paddingLeft="4dp"
android:paddingRight="4dp" />
<ImageView
android:id="#+id/home_team_event_img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentTop="true"
android:layout_centerVertical="true"
android:layout_marginRight="4dp"
android:layout_toLeftOf="#+id/live_match_minute" />
<ImageView
android:id="#+id/away_team_event_img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="false"
android:layout_centerVertical="true"
android:layout_marginLeft="4dp"
android:layout_toRightOf="#+id/live_match_minute" />
<TextView
android:id="#+id/away_team_event_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="false"
android:layout_centerVertical="true"
android:layout_toRightOf="#+id/away_team_event_img"
android:paddingLeft="4dp"
android:paddingRight="4dp" />
Why is it that the rows in my list are always set on the same size, no matter what I put in?
This will NOT work.
This is what you should do.
<?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="wrap_content" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="150dp"
android:background="#drawable/background_button" >
<TextView
android:id="#+id/live_match_minute"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="82'" />
</RelativeLayout>
</RelativeLayout>
Basically, add another layout and specify the height to that layout.
When working with adapter views specifying a height for the root layout doesn't work.
I want to have a single "Textview" and 2 "Edittext" in a single row.I have tried the following code:
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="horizontal"
>
<TextView
android:id="#+id/vegtext"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
<EditText
android:id="#+id/vegquantity"
android:hint="Qty"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_weight="1"
/>
<EditText
android:id="#+id/vegprice"
android:layout_width="100dp"
android:layout_height="100dp"
android:hint="price"
android:layout_weight="1"
/>
</LinearLayout>
Getview in adapter:
#Override
public View getView(int position, View convertview, ViewGroup parent)
{
VeglistHolder holder;
// TODO Auto-generated method stub
if(convertview == null)
{
LayoutInflater inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertview = inflater.inflate(R.layout.veglistrow, null);
holder = new VeglistHolder();
holder.text = (TextView) convertview
.findViewById(R.id.vegtext);
holder.Qtyedit = (EditText) convertview
.findViewById(R.id.vegquantity);
holder.priceedit = (EditText) convertview
.findViewById(R.id.vegprice);
convertview.setTag(holder);
}
else
{
holder = (VeglistHolder) convertview.getTag();
}
holder.text.setText(vegitems[position]);
return convertview;
}
But the Edittext is not there in the row. Also some blank space is coming below the "TExtview" .I searched for "Lots of" post regarding this but i cant solve this.Please help me to solve this..Thanks in advance.
Try to use weightSum in main layout for equal partition as below
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:weightSum="3"
android:orientation="vertical" >
Use a Realative layout. Modify the attributes to suit your requirement
<?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/textView1"
android:layout_width="60dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="58dp"
android:text="TextView" />
<EditText
android:id="#+id/editText1"
android:layout_width="60dp" //set to whatever you desire
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/textView1"
android:layout_alignBottom="#+id/textView1"
android:layout_marginLeft="30dp"
android:layout_toRightOf="#+id/textView1"
android:ems="10" >
<requestFocus />
</EditText>
<EditText
android:id="#+id/editText2"
android:layout_width="60dp"// //set to whatever you desire
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/editText1"
android:layout_alignBottom="#+id/editText1"
android:layout_alignParentRight="true"
android:layout_marginRight="70dp"
android:ems="10"
android:inputType="textPersonName" />
</RelativeLayout>
Well your problem is that you set the width and the height of the TextView to fill parent