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>
Related
I am using a LayoutInflater to fill out a grid view using a GridAdapter, but when i try to place a textView below another textView within the layout i am inflating, it ends up being above my textView instead of below. When i change it to layout_above instead, it doesnt even appear on the screen.
Layout that i inflate:
<?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:id="#+id/menuBookModel">
<ImageView
android:id="#+id/bookImage"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_margin="5dp"/>
<TextView
android:id="#+id/bookName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Test Text"
android:textSize="20sp"
android:textColor="#color/colorPrimaryDark"
android:layout_centerInParent="true"/>
<TextView
android:id="#+id/personalTag"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/bookName"
android:text="(Personal)"
android:layout_centerHorizontal="true"
android:textColor="#color/colorPrimaryDark"
android:textSize="15sp" />
</RelativeLayout>
My java code where i am inflating:
#Override
public View getView(int i, View view, ViewGroup viewGroup) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if(view == null){
view = inflater.inflate(R.layout.menu_book_model, null);
}
TextView bookName = view.findViewById(R.id.bookName);
TextView personalTag = view.findViewById(R.id.personalTag);
ImageView bookImage = view.findViewById(R.id.bookImage);
bookImage.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
String s = String.valueOf(view.getTag());
aListener.chooseBook(s);
}
});
int id = context.getResources().getIdentifier(books[i], "string", context.getPackageName());
//if id == 0 the book is custom, and therefore it has the custom name
if(id == 0){
bookName.setText(books[i]);
} else {
bookName.setText(context.getString(id));
personalTag.setVisibility(View.GONE);
}
bookImage.setBackgroundColor(Color.rgb(random.nextInt(255),random.nextInt(255),random.nextInt(255)));
bookImage.setTag(books[i]);
return view;
}
How it looks in the preview:
Preview
But this is how it look in practice:
In practice
You also need to handle personalTag visibility when the id is 0, because it may not be visible when the view is being recycled:
if(id == 0){
bookName.setText(books[i]);
personalTag.setVisibility(View.VISIBLE);
} else {
bookName.setText(context.getString(id));
personalTag.setVisibility(View.GONE);
}
Also avoid setting your root RelativeLayout with match_parent as height, they usually break in AdapterViews, try wrap_content or any hard values, or adjust your layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="100dp"
android:id="#+id/menuBookModel">
<ImageView
android:id="#+id/bookImage"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_margin="5dp"/>
<TextView
android:id="#+id/bookName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Test Text"
android:layout_centerInParent="true"
android:textSize="20sp"
android:textColor="#color/colorPrimaryDark"/>
<TextView
android:id="#+id/personalTag"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/bookName"
android:layout_centerHorizontal="true"
android:text="(Personal)"
android:textColor="#color/colorPrimaryDark"
android:textSize="15sp" />
</RelativeLayout>
I've been trying to add radio buttons inside a radio group in a listview.
So, if I click a radio button it checks it but if I click another one, it doesn't remove the previous selection. I'm a beginner in android so forgive me If I'm doing something terribly wrong.
This is my Main Activity and I have the radio group outside the list
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingTop="20dp">
<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/car_list_radio_group">
<ListView
android:id="#+id/vehicle_list"
android:clickable="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content"></ListView>
</RadioGroup>
</LinearLayout>
This is my custom view for each item on the list
<?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:alwaysDrawnWithCache="true"
android:backgroundTint="#ffffff">
<RadioButton
android:id="#+id/car_selected"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:buttonTint="#color/tesla_red"
android:padding="10dp"
android:text=""
android:textColor="#android:color/white"
android:textSize="16sp"
android:textStyle="bold" />
<TextView
android:id="#+id/vin"
android:layout_width="183dp"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_below="#+id/car_selected"
android:layout_marginStart="30dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:textColor="#android:color/white"
android:textSize="12sp" />
</RelativeLayout>
This is my adapter for the list
private final class VehiclesAdapter extends BaseAdapter {
LayoutInflater inflter;
ArrayList<VehicleItem> vehiclesArray;
public VehiclesAdapter(Context applicationContext, ArrayList<VehicleItem> items) {
vehiclesArray = items;
inflter = (LayoutInflater.from(applicationContext));
}
#Override
public int getCount() {
return vehiclesArray.size();
}
#Override
public Object getItem(int position) {
return null;
}
#Override
public long getItemId(int position) {
return Long.parseLong(vehiclesArray.get(position).getId());
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
VehicleHolder holder;
VehicleItem vehicleItem = vehiclesArray.get(position);
if (convertView == null) { // if convertView is null
convertView = inflter.inflate(R.layout.vehicle_item, parent, false);
holder = new VehicleHolder();
holder.name = convertView.findViewById(R.id.car_selected);
holder.vin = convertView.findViewById(R.id.vin);
// initialize views
convertView.setTag(holder); // set tag on view
} else {
holder = (VehicleHolder) convertView.getTag();
// if not null get tag
// no need to initialize
}
if(vehicleItem.getId().equals(currentVehicle)){
holder.name.setChecked(true);
}
holder.name.setText(vehicleItem.getName());
holder.vin.setText(vehicleItem.getVin());
//update views here
return convertView;
}
}
If you need to see something else please let me know.
RadioGroup is a LinearLayout and is meant to have RadioButton children in order to handle check/uncheck properly. You will have to drop it and handle the check/uncheck logic yourself from the adapter.
add this in your list_item.xml
You will get radioGroup in each row
And remove RadioGroup from main_activity.xml
hope this will help you...
<?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:alwaysDrawnWithCache="true"
android:backgroundTint="#ffffff">
<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/car_list_radio_group">
<RadioButton
android:id="#+id/car_selected"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:buttonTint="#color/tesla_red"
android:padding="10dp"
android:text=""
android:textColor="#android:color/white"
android:textSize="16sp"
android:textStyle="bold" />
<RadioButton
android:id="#+id/car_not_selected"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:layout_torightof="#+id/car_selected"
android:buttonTint="#color/tesla_red"
android:padding="10dp"
android:text=""
android:textColor="#android:color/white"
android:textSize="16sp"
android:textStyle="bold"
</RadioGroup>
<TextView
android:id="#+id/vin"
android:layout_width="183dp"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_below="#+id/car_selected"
android:layout_marginStart="30dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:textColor="#android:color/white"
android:textSize="12sp" />
</RelativeLayout>
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
I am trying to add a listview to an existing android fragment. I made a layout xml file for items in the listview, modified the previous fragment.xml, wrote a new arrayadapter and added something to the fragment.java. But whenever I call the notifyDataSetChanged() method in the fragment.java, I got an error: android.content.res.Resources$NotFoundException: String resource ID #0x0, and then the app crashes. Below please find my codes.
layout.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="7dp">
<ImageView
android:layout_width="72dp"
android:layout_height="72dp"
android:id="#+id/iv_checkIcon"
android:layout_margin="7dp"
android:background="#EEEEEE"
android:contentDescription="Provider icon"
/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_toRightOf="#id/iv_checkIcon"
android:layout_marginTop="4dp"
android:layout_marginBottom="4dp"
android:layout_marginLeft="5dp"
>
<TextView
android:layout_width="200dp"
android:layout_height="wrap_content"
android:id="#+id/tv_checkName"
android:text="Provider name"
android:textSize="20dp"
/>
<TextView
android:layout_width="250dp"
android:layout_height="wrap_content"
android:id="#+id/tv_checkInDate"
android:text="Check In Date"
android:textSize="14dp"
android:textColor="#888888"
android:layout_marginTop="4dp"/>
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/tv_checkPoints"
android:layout_alignParentRight="true"
android:text="100分"
android:layout_marginTop="10dp"
android:layout_marginRight="10dp"
android:textSize="18dp"
android:textColor="#CF1A12"
/>
</RelativeLayout>
fragment.xml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".fragment.MeActivity">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/me_bg2"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/fake_head"
android:layout_centerHorizontal="true"
android:layout_marginTop="40dp"
android:id="#+id/iv_fake_head"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_below="#id/iv_fake_head"
android:text="--"
android:textSize="22dp"
android:textColor="#ffffff"
android:layout_marginTop="15dp"
android:id="#+id/tv_name"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_below="#id/tv_name"
android:text="积分"
android:textColor="#ffffff"
android:layout_marginTop="15dp"
android:textSize="20dp"
android:background="#drawable/me_points_bg"
android:id="#+id/tv_points"
/>
</RelativeLayout>
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/lv_histories"
android:layout_gravity="bottom" />
</FrameLayout>
Arrayadapter.java
public class RecordArrayAdapter extends ArrayAdapter<CheckInRecord.CheckInRec> {
private int resourceId;
private Context context;
private List<CheckInRecord.CheckInRec> checkInRecList;
public RecordArrayAdapter(Context context, int resourceId, List<CheckInRecord.CheckInRec> checkInRecList)
{
super(context, resourceId, checkInRecList);
this.resourceId = resourceId;
this.context = context;
this.checkInRecList = checkInRecList;
}
public View getView(int position, View convertView, ViewGroup parent)
{
if (convertView == null){
LayoutInflater inflater = ((Activity)context).getLayoutInflater();
convertView = inflater.inflate(resourceId, parent, false);
}
TextView textViewName = (TextView) convertView.findViewById(R.id.tv_checkName);
TextView textViewCheckInDate = (TextView) convertView.findViewById(R.id.tv_checkInDate);
TextView textViewPoints = (TextView) convertView.findViewById(R.id.tv_checkPoints);
ImageView imageViewIcon = (ImageView) convertView.findViewById(R.id.iv_checkIcon);
CheckInRecord.CheckInRec checkInRec = checkInRecList.get(position);
textViewName.setText(checkInRec.providerName);
textViewCheckInDate.setText(checkInRec.checkInDate);
textViewPoints.setText(checkInRec.providerPoints);
ImageLoader.getInstance().displayImage(checkInRec.providerIcon, imageViewIcon, Utility.displayImageOptions);
return convertView;
}
public int getIsPrize(int position) {return (this.checkInRecList.get(position).isPrize);}
}
fragment.java
public class MeFragment extends Fragment implements ApiRequestDelegate {
private TextView textViewName;
private TextView textViewPoints;
private ProgressDialog progressDialog;
private RecordArrayAdapter recordArrayAdapter;
private List<CheckInRecord.CheckInRec> checkInRecList = new ArrayList<CheckInRecord.CheckInRec>();
public MeFragment() {
// Required empty public constructor
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ApiManager.getInstance().checkInHistories(AppDataManager.getInstance().getUserToken(), AppDataManager.getInstance().getUserPhone(),
Utility.getPictureSize(), this);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View fragmentView = inflater.inflate(R.layout.fragment_me, container, false);
textViewName = (TextView) fragmentView.findViewById(R.id.tv_name);
textViewPoints = (TextView) fragmentView.findViewById(R.id.tv_points);
ListView listViewRec = (ListView) fragmentView.findViewById(R.id.lv_histories);
recordArrayAdapter = new RecordArrayAdapter(this.getActivity(), R.layout.row_record, checkInRecList);
listViewRec.setAdapter(recordArrayAdapter);
return fragmentView;
}
#Override
public void apiCompleted(ApiResult apiResult, HttpRequest httpRequest) {
if (progressDialog!=null){
progressDialog.dismiss();
}
if (!apiResult.success){
ApiManager.handleMessageForReason(apiResult.failReason, getActivity());
return;
}
CheckInRecord checkInRecord = (CheckInRecord) apiResult.valueObject;
if (checkInRecord != null){
textViewName.setText(checkInRecord.userName);
textViewPoints.setText(String.format("积分%d分", checkInRecord.userPoints));
this.checkInRecList.clear();
this.checkInRecList.addAll(checkInRecord.checkInRecList);
recordArrayAdapter.notifyDataSetChanged();
}
}
}
Make sure checkInRec.providerName, checkInRec.checkInDate and checkInRec.providerPoints values that you set as TextView text have a type of String and cast it to String if it's integer.
// cast to String if checkInRec.checkInDate is integer
textViewPoints.setText(String.valueOf(checkInRec.providerPoints));
UPD:
It seems ListView is located behind header view. Try to change root view of fragment.xml from FrameLayout to LinearLayout with android:orientation="vertical" attribute. Like this:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".fragment.MeActivity">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/me_bg2"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/fake_head"
android:layout_centerHorizontal="true"
android:layout_marginTop="40dp"
android:id="#+id/iv_fake_head"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_below="#id/iv_fake_head"
android:text="--"
android:textSize="22dp"
android:textColor="#ffffff"
android:layout_marginTop="15dp"
android:id="#+id/tv_name"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_below="#id/tv_name"
android:text="积分"
android:textColor="#ffffff"
android:layout_marginTop="15dp"
android:textSize="20dp"
android:background="#drawable/me_points_bg"
android:id="#+id/tv_points"
/>
</RelativeLayout>
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/lv_histories"
android:layout_gravity="bottom" />
</LinearLayout>
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?