so i recently started to get my hands dirty with android development and after some wrestling and failing to get this working i thought id run it by you guys and gals. i hope any of you has solved a similar problem
I have a fragment with a layout that is to display a textview and a list of items as follow:
Historical data
Item1 20
item2 30
item3 40
This includes a button on the action bar which will be implemented to allow the user to add more items and a number. I am having trouble achieving the above behavior. I was able to implement a adapter which ended up displaying as follow:
Historical data
Item1 20
Historical data
item2 30
Historical data
item3 40
Any ideas how could i do the above?
Myfragment.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="wrap_content"
android:orientation="vertical" >
<TextView
style="?android:listSeparatorTextViewStyle"
android:textSize="18sp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/weight_history_label" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView android:id="@+id/item"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textStyle="bold"
android:paddingLeft="4dp"
android:paddingRight="4dp"
android:text="Weigh in Date" />
<TextView
android:id="@+id/amount"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/item"
android:inputType="numberDecimal"
android:paddingLeft="4dp"
android:paddingRight="4dp"
android:paddingTop="4dp"
android:text="Weight Amount " />
</RelativeLayout>
</LinearLayout>
I have a class of items:
Items.java
public class NewEntry {
private String mName;
private int mNumber;
public NewEntry(){
....
}
getters/setters }
Then in my fragment.java
myFragment.java
public class MyFragment extends ListFragment {
private ArrayList<Items> mEntries;
MenuItem test;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//get all the entries and store them on mEntries
mEntries = EntriesLab.get(getActivity()).getWeighInEntries();
setHasOptionsMenu(true);
ItemAdapter adapter = new ItemAdapter(mEntries);
setListAdapter(adapter);
}
/interface to talk to activity
public interface onButtonClicked {
public void onWeighInButtonClicked(View v);
}
private class ItemAdapter extends ArrayAdapter<Items> {
public ItemAdapter(ArrayList<Items> items) {
super(getActivity(), 0, items);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// If we weren't given a view, inflate one
if (convertView == null) {
convertView = getActivity().getLayoutInflater()
.inflate(R.layout.Myfragment, null);
}
Items c = getItem(position);
TextView titleDateView =
(TextView)convertView.findViewById(R.id.name);
titleDateView.setText(c.getDate().toString());
// Log.i("WeighInFragment: ", "###current Weight " + c.getDate().toString());
TextView titleWeightView =
(TextView)convertView.findViewById(R.id.witem);
titleWeightView.setText(""+c.getWeight());
return convertView;
}
}
}
so what i would like to do is implement my Label only once and then display the list of items! no matter what i try i always get a list of : label item value label item value label item value ...