I want to do a custom view coming from an XML.
Here's my XML :
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/movieTitle"
android:text="#string/movietitle"
android:textSize="35dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
/>
<com.galite.headliner.views.LoaderImageView
android:id="#+id/moviePoster"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/movieTitle"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:layout_marginBottom="20dp"
android:contentDescription="#string/poster"
/>
<TextView
android:id="#+id/movieDescription"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/description"
android:layout_below="#id/moviePoster"
android:gravity="center"
/>
</RelativeLayout>
And i want to inflate to a custom view because i need to use methods like onClick and everything.
Here's my constructor :
public MyView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
this.context = context;
initializeView();
}
public void initializeView(){
inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = inflater.inflate(R.layout.movie, null);
}
How can i make MyView equal to v ?
You'll have to attach the inflated view v to MyView like this:
v = inflater.inflate(R.layout.movie, this, true);
If you want that exact layout then make MyView to extend RelativeLayout and modify the xml layout like this:
<merge xmlns:android="http://schemas.android.com/apk/res/android" >
<TextView
android:id="#+id/movieTitle"
android:text="#string/movietitle"
android:textSize="35dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
/>
<com.galite.headliner.views.LoaderImageView
android:id="#+id/moviePoster"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/movieTitle"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:layout_marginBottom="20dp"
android:contentDescription="#string/poster"
/>
<TextView
android:id="#+id/movieDescription"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/description"
android:layout_below="#id/moviePoster"
android:gravity="center"
/>
</merge>
Related
I am trying to create a FrameLayout that contains other FrameLayouts. I have created an EditorView class that extends FrameLayout, and I want it to display FileView, another class that extends FrameLayout. But in Android Studio preview I get an blank view. What am I doing wrong.
This is the ediorview_activity.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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">
<com.itsvaske.webio.Views.LineView
android:id="#+id/html1"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<com.itsvaske.webio.Views.LineView
android:id="#+id/html2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/html1" />
<com.itsvaske.webio.Views.LineView
android:id="#+id/html3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/html2" />
<com.itsvaske.webio.Views.LineView
android:id="#+id/html4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/html3" />
<com.itsvaske.webio.Views.LineView
android:id="#+id/html5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/html4" />
<com.itsvaske.webio.Views.LineView
android:id="#+id/html6"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/html5" />
<com.itsvaske.webio.Views.LineView
android:id="#+id/html7"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/html6" />
</RelativeLayout>
This is lineview_layout.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">
<TextView
android:id="#+id/lineNumber"
android:layout_width="30dp"
android:layout_height="40dp"
android:layout_weight="0"
android:gravity="center"
android:text="1"
android:textColor="#000000"
android:textSize="20sp" />
<EditText
android:id="#+id/line"
android:layout_width="wrap_content"
android:layout_height="42dp"
android:layout_weight="3"
android:background="#null"
android:ems="10"
android:hint="#string/typeyourline"
android:inputType="textPersonName"
android:minHeight="32dp"
android:textColorHint="#546E7A" />
</LinearLayout>
This is EditorView class:
public class EditorView extends FrameLayout {
private Context mContext;
private AttributeSet mAttributeSet;
public EditorView(#NonNull Context context, #Nullable AttributeSet attrs) {
super(context, attrs);
this.mContext = context;
this.mAttributeSet = attrs;
initView();
}
private void initView() {
View view = View.inflate(mContext, R.layout.editor_start_html_layout, this);
LineView line1 = view.findViewById(R.id.html1);
LineView line2 = view.findViewById(R.id.html2);
LineView line3 = view.findViewById(R.id.html3);
LineView line4 = view.findViewById(R.id.html4);
LineView line5 = view.findViewById(R.id.html5);
LineView line6 = view.findViewById(R.id.html6);
LineView line7 = view.findViewById(R.id.html7);
line1.setLineNumber(1);
line1.setLineContents("<html>");
line2.setLineNumber(2);
line2.setLineContents("<head>");
line3.setLineNumber(3);
line3.setLineContents(" <title></title>");
line4.setLineNumber(4);
line4.setLineContents("</head>");
line5.setLineNumber(5);
line5.setLineContents("<body>");
line6.setLineNumber(6);
line6.setLineContents("</body>");
line7.setLineNumber(7);
line7.setLineContents("</html>");
}
}
And In preview I get this:
I want to be able to perform onClickListner on root RelativeLayout called "rl". Not it does not work I suspect it can be because of MotionLayout as a children. How to solve that?
Here is what I have done so far, my code.
ShowNoteActivity.java
(...)
#Override
protected void onCreate(#Nullable Bundle savedInstanceState) {
(...)
RelativeLayout rl = findViewById(R.id.rl);
rl.setOnClickListener(view -> {
Toast.makeText(this, "abc", Toast.LENGTH_SHORT).show();
});
}
show_note_activity.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/rl"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:focusable="true">
<pl.jawegiel.simplenotepad.CustomMotionLayout
android:id="#+id/motion_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="false"
android:focusable="false"
app:layoutDescription="#xml/show_note_activity_scene">
<TextView
android:id="#+id/note_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:clickable="false"
android:duplicateParentState="true"
android:focusable="false"
android:gravity="center"
android:text="#string/note_title"
android:textColor="?attr/myTextColor"
android:textSize="18sp"
android:textStyle="bold"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/note_title_value"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/textView3"
android:clickable="false"
android:duplicateParentState="true"
android:focusable="false"
android:gravity="top|left"
android:hint="#string/enter_title"
android:lines="2"
android:maxLines="10"
android:minHeight="48dp"
android:textColor="?attr/myTextColor"
android:textColorHint="?attr/myHintTextColor"
android:textSize="18sp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="#id/note_title" />
<TextView
android:id="#+id/note_desc"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/note_title_value"
android:layout_marginTop="10dp"
android:clickable="false"
android:duplicateParentState="true"
android:focusable="false"
android:gravity="center"
android:text="#string/note_desc"
android:textColor="?attr/myTextColor"
android:textSize="18sp"
android:textStyle="bold"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#id/note_title_value" />
<androidx.core.widget.NestedScrollView
android:id="#+id/nestedScrollView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="false"
android:focusable="false"
app:layout_constraintTop_toBottomOf="#id/note_desc">
<RelativeLayout
android:id="#+id/rl2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="false"
android:focusable="false">
<TextView
android:id="#+id/note_desc_value"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="false"
android:focusable="false"
android:textColor="?attr/myTextColor"
android:textColorHint="?attr/myHintTextColor"
android:textSize="18sp" />
</RelativeLayout>
</androidx.core.widget.NestedScrollView>
</pl.jawegiel.simplenotepad.CustomMotionLayout>
</RelativeLayout>
CustomMotionLayout.java
public class CustomMotionLayout extends MotionLayout {
public CustomMotionLayout(Context context) {
super(context);
}
public CustomMotionLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
public CustomMotionLayout(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
#Override
public boolean onInterceptTouchEvent(MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_MOVE) {
return super.onInterceptTouchEvent(event);
}
return false;
}
}
show_note_activity_scene.xml
<?xml version="1.0" encoding="utf-8"?>
<MotionScene xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<ConstraintSet android:id="#+id/start">
<Constraint
android:id="#id/note_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<Constraint
android:id="#id/note_title_value"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="#id/note_title"/>
<Constraint
android:id="#id/note_desc"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#id/note_title_value"/>
</ConstraintSet>
<ConstraintSet android:id="#+id/end">
<Constraint
android:id="#id/note_title"
android:layout_width="match_parent"
android:layout_height="1dp"
android:alpha="0.0"/>
<Constraint
android:id="#id/note_title_value"
android:layout_width="match_parent"
android:layout_height="1dp"
android:alpha="0.0"/>
<Constraint
android:id="#id/note_desc"
android:layout_width="match_parent"
android:layout_height="1dp"
android:alpha="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
</ConstraintSet>
<Transition
app:constraintSetEnd="#id/end"
app:constraintSetStart="#id/start"
app:duration="1000">
<OnSwipe
app:touchAnchorSide="top"
app:dragDirection="dragUp"
app:moveWhenScrollAtTop="true"
app:touchAnchorId="#id/nestedScrollView"/>
<KeyFrameSet>
</KeyFrameSet>
</Transition>
</MotionScene>
If you want to click on parent you should disable motionlayout transition and do your transition programmatically with one button or ...
Disable motion layout:
motionLayout.getTransition(R.id.yourTransition).setEnable(false)
If you must to use onSwipe in your project you can disable transition after collapsing motionlayout and return layout to top programmatically and when expand enable motionlayout transition.
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>
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 am trying to make a reusable header. Here is my XML.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/bg" >
<ImageButton
android:id="#+id/imagebuttonforheader"
android:layout_height="50dp"
android:layout_width="50dp"
android:layout_alignParentLeft="true"
android:background="#drawable/back_button"
/>
<ImageButton
android:id="#+id/imagebuttonforheader"
android:layout_height="50dp"
android:layout_width="50dp"
android:layout_alignParentRight="true"
android:background="#drawable/forward_button"
/>
</RelativeLayout>
I made a class for it:
public class Header extends RelativeLayout {
Context context;
Activity activity;
public Header(Context context, AttributeSet attrs) {
super(context, attrs);
this.context = context;
LayoutInflater li = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
li.inflate(R.layout.header, null, false);
}
}
And then added this layout into my main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<my.testy.view.Header
android:id="#+id/headerOnMain"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true" >
</my.testy.view.Header>
<TextView
android:id="#+id/textView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/headerOnMain"
android:text="#string/hello" />
</RelativeLayout>
But it's not showing up on the application.
What am I doing wrong here?
You have to attached your inflated layout to your custom class:
li.inflate(R.layout.header, this, true);