I want to programmatically add a view to ScrollView that is apart of a Fragment layout.
I have attempeted the following code:
public class MessageDetail extends Fragment {
View layout;
TextView messageText;
Conversation conversation;
List<Message> messages;
LayoutInflater inflater;
ViewGroup container;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// TODO Auto-generated method stub
this.inflater = inflater;
this.container = container;
layout = inflater.inflate(R.layout.messenger_detail, container,
false);
messageText = (TextView) layout.findViewById(R.id.tvMessage);
return layout;
}
public void loadConversation(Conversation conversation) {
messageText.setText(conversation.getSubject());
LinearLayout messagesView = (LinearLayout)layout.findViewById(R.id.llMessageDetail);
LinearLayout messageBody = new LinearLayout(getActivity());
View body = inflater.inflate(R.layout.messagebody, container);
messagesView.addView(body);
}
}
messagebody.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/llMessageBody"
android:layout_width="fill_parent"
android:layout_margin="5dp"
android:layout_height="200dp"
android:background="#353535"
android:orientation="vertical" >
<TextView
android:id="#+id/tvMSBodyFrom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20dp"
android:text="Research Station:"
android:textColor="#FFFFAA"
/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/tomatohigh"
/>
</LinearLayout>
message_detail.xml
<?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:background="#d3d6da"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="100dp"
android:background="#FFAA00" >
<TextView
android:id="#+id/tvMessage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="20dp"
android:text="Select a Message:"
android:textColor="#353535"
android:textSize="30dp" />
</LinearLayout>
<ScrollView
android:id="#+id/svMessageDetail"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#9900AA"
android:minHeight="300dp" >
<LinearLayout
android:id="#+id/llMessageDetail"
android:layout_width="fill_parent"
android:orientation="vertical"
android:layout_height="wrap_content" >
</LinearLayout>
</ScrollView>
</LinearLayout>
The final implementaion would see me loop through a list of messages and add the a view with the message_body layout and change each part of the layout to the correct values of each message
Any ideas how to achieve this?
You can do like this:
YourView varView = new YourView(this);
myButton.setLayoutParams(new YourLayout.LayoutParams());
yourParentLayout.addView(varView);
Example: Add a button in parent linear layout
Button myButton = new Button(this);
myButton.setLayoutParams(new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.FILL_PARENT,
LinearLayout.LayoutParams.FILL_PARENT));
myLayout.addView(myButton);
Related
i would like to add to a LinearLayout some imageViews dynamically in my app.
My following code doesn't show errors and prints what it is supposed to on logcat each time an ImageView is added from java code.
My problem is that when i run the app the images don't appear on screen....any idea where i am doing wrong ?
thanks a lot.
public class MesListesFragment extends Fragment {
private RecyclerView mes_listes_recyclerView;
private ArrayList<ListItem> liste_items;
private LinearLayout list_card_categories;
#Nullable
#Override
public View onCreateView(#NonNull LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.mes_listes_fragment, container, false);
View view2 = inflater.inflate(R.layout.list_item, container, false);
mes_listes_recyclerView = view.findViewById(R.id.mes_listes_recyclerView);
list_card_categories = view2.findViewById(R.id.list_card_recyclerView);
liste_items = new ArrayList<>();
for (int i = 0; i < 10; i ++){
liste_items.add(new ListItem("Liste des ploucs", "18 Août 198" + i));
}
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getContext());
mes_listes_recyclerView.setLayoutManager(linearLayoutManager);
mes_listes_recyclerView.setAdapter(new ListViewAdapter(getContext(), liste_items));
for (int i = 0; i < 8; i++){
ImageView image = new ImageView(getContext());
image.setImageResource(R.drawable.user);
list_card_categories.addView(image);
Log.d("view created", "...");
}
return view;
}
}
Here is the xml, the file's called list_item.xml :
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="150dp"
android:layout_marginHorizontal="10dp"
android:layout_marginTop="10dp"
app:cardCornerRadius="10dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/list_card_first_container"
android:layout_width="match_parent"
android:layout_height="100dp"
android:baselineAligned="false"
android:orientation="horizontal"
android:weightSum="100">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="50"
android:gravity="center"
android:orientation="vertical">
<TextView
android:id="#+id/list_card_textView_nom_liste"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Nom de la liste"></TextView>
<TextView
android:id="#+id/list_card_textView_date_liste"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Date liste"></TextView>
</LinearLayout>
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="50">
<LinearLayout
android:id="#+id/list_card_recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="50"
android:gravity="center"
android:orientation="horizontal">
</LinearLayout>
</HorizontalScrollView>
</LinearLayout>
<LinearLayout
android:id="#+id/list_card_second_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/list_card_first_container"
android:gravity="center"
android:orientation="horizontal"
android:paddingVertical="5dp">
<Button
android:id="#+id/list_card_button_editer"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_marginEnd="20dp"
android:background="#color/bleu_fb"
android:text="#string/editer"></Button>
<Button
android:id="#+id/list_card_button_supprimer"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:background="#android:color/holo_red_light"
android:text="#string/supprimer"></Button>
</LinearLayout>
</RelativeLayout>
</androidx.cardview.widget.CardView>
I am trying to replace the content of frame_layout with a view of fragment.
I used to do that by just using transaction.replace but it just put the view on the top of the main content.
Here is the code:
That's where I replace the frame_layout whose ID is contain:
VideosFragment videosFragment = new VideosFragment();
Bundle bundle = new Bundle();
bundle.putCharSequence("Character", view.getContentDescription());
videosFragment.setArguments(bundle);
FragmentTransaction transaction = fragmentManager.beginTransaction();
transaction.replace(R.id.contain , videosFragment).addToBackStack(null).commit();
here is the xml of main_Activity
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.shobakyDC.muchannel.MainActivity">
<FrameLayout
android:id ="#+id/contain"
android:layout_width="match_parent"
android:background="#drawable/islamic_green"
android:layout_height="match_parent">
<ProgressBar
android:id="#+id/progressBar2"
style="?android:attr/progressBarStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />
<GridView
android:id="#+id/gridview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:horizontalSpacing="10dp"
android:numColumns="2"
android:paddingStart="50dp"
android:paddingTop="10dp"
android:verticalSpacing="10dp"
android:paddingRight="0dp"
android:paddingLeft="50dp"
android:paddingEnd="0dp">
</GridView>
</FrameLayout>
<android.support.design.widget.NavigationView
android:id="#+id/Navigator"
android:layout_width="wrap_content"
android:layout_height="match_parent"
app:headerLayout="#layout/header"
android:layout_gravity="start"
android:background="#android:color/white"
app:itemTextColor="#color/navcolor"
app:itemIconTint="#color/navcolor"
app:menu="#menu/navigationmenu">
</android.support.design.widget.NavigationView>
the video_fragment:
public class VideosFragment extends Fragment {
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.videofragment_layout , container , false);
Bundle args = getArguments();
TextView textView = view.findViewById(R.id.textView);
textView.setText(args.getString("Character"));
return view;
}
}
In xml of Main Activity, you have to make an empty FrameLayout with an ID like this:
<FrameLayout
android:id ="#+id/contain"
android:layout_width="match_parent"
android:background="#drawable/islamic_green"
android:layout_height="match_parent">
</FrameLayout>
and then make a separate xml layout for this fragment. Now you have to replace this fragment layout with frame layout in Main Activity.
I want to realize the Gallery using HorizontalScrollView. But it throws java.lang.illegalStateException. The logcat hint that the HorizontalScrollView can host only one direct child. I only set one direct child - LinearLayout to it. I searched from the Internet, but haven't solved the problem. Hope anyone can help me. Belows are the code.
xml
<HorizontalScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="8dp"
android:scrollbars="none"
>
<LinearLayout
android:id="#+id/gallery_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
</LinearLayout>
</HorizontalScrollView>
item xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingTop="10dp"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:paddingBottom="20dp"
>
<ImageView
android:id="#+id/trend_item_imageview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="8dp"
android:src="#drawable/gallery0"
/>
<TextView
android:id="#+id/trend_item_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="权利的游戏"
android:textSize="16sp"
/>
</LinearLayout>
Fragment
public class DiscoverFragment extends Fragment {
private int[] imageResources = {R.drawable.gallery0, R.drawable.gallery1, R.drawable.gallery2,
R.drawable.gallery3, R.drawable.gallery4, R.drawable.gallery5};
private String[] imageDescriptions = {"权利的游戏", "风吹的风景", "插画背景", "美食君", "吃", "你好四月"};
private List<TrendItem> trendItemList;
private LinearLayout galleryLayout;
public DiscoverFragment() {
// Required empty public constructor
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_discover, container, false);
ButterKnife.bind(this, view);
galleryLayout = ButterKnife.findById(view, R.id.gallery_layout);
initData();
setView();
return view;
}
private void initData(){
trendItemList = new ArrayList<>();
for (int i = 0; i < imageResources.length; i++){
TrendItem trendItem = new TrendItem();
trendItem.setImageResource(imageResources[i]);
trendItem.setText(imageDescriptions[i]);
trendItemList.add(trendItem);
}
}
private void setView(){
for (int i = 0; i < trendItemList.size(); i++){
LayoutInflater inflater = LayoutInflater.from(getContext());
View view = inflater.inflate(R.layout.trend_item, galleryLayout, false);
ImageView trendItemImageView = ButterKnife.findById(view, R.id.trend_item_imageview);
TextView trendItemTextView = ButterKnife.findById(view, R.id.trend_item_textview);
trendItemImageView.setImageResource(trendItemList.get(i).getImageResource());
trendItemTextView.setText(trendItemList.get(i).getText());
galleryLayout.addView(view);
}
}
}
Meaning, you have to add the ImageView, TextView to the Linearlayout. when you add the imageview you are adding it to the HorizontalScrollview which also has a LinearLayout in it their by adding 2 child elements to the HorizontalScrollView which you cannot do.
<HorizontalScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="8dp"
android:scrollbars="none">
<LinearLayout
android:id="#+id/gallery_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="#+id/trend_item_imageview"
android:layout_width="your_size"
android:layout_height="your_size"
android:src="#drawable/gallery0"/>
<TextView
android:id="#+id/trend_item_textview"
android:layout_width="your_size"
android:layout_height="your_size"
android:text="权利的游戏"
android:textSize="16sp"/>
</LinearLayout>
</HorizontalScrollView>
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 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>