I have two java class and two xml file for listview with buttons.I want to pass the data of Corresponding text in the row of listview to the linear layout.
here is the code of my first java class.
public class Items_momo extends Activity {
LinearLayout myLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_items_momo);
ArrayList<String> list = new ArrayList<String>();
list.add("Veg Steam Momo");
list.add("Veg C-Momo");
list.add("Veg Fry Momo");
list.add("Veg Kothey Momo");
list.add("Buff Steam Momo");
list.add("Buff Fry Momo");
list.add("Buff Kothey Momo");
list.add("Buff C-Momo");
list.add("Chicken Steam Momo");
list.add("Chicken Fry Momo");
list.add("Chicken Kothey Momo");
list.add("Chicken C-Momo");
list.add("Paneer Steam Momo");
list.add("Paneer Fry Momo");
list.add("Paneer Kothey Momo");
list.add("Paneer C-Momo");
MyCostumAdapter adapter = new MyCostumAdapter(list, this);
ListView lView = (ListView) findViewById(R.id.momo_list);
lView.setAdapter(adapter);
}
}
and the second class code is
public class MoMoCostumAdapter extends BaseAdapter implements ListAdapter {
LinearLayout myLayout;
private ArrayList<String> list =new ArrayList<String>();
private Context context;
public MoMoCostumAdapter(ArrayList<String> list,Context context){
this.list = list;
this.context = context;
}
@Override
public int getCount() {
return list.size();
}
@Override
public Object getItem(int pos) {
return list.get(pos);
}
@Override
public long getItemId(int pos) {
return 0;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
View view = convertView;
if (view == null) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(R.layout.costum_momolayout, null);
}
final TextView listItemText = (TextView)view.findViewById(R.id.list_item_string);
listItemText.setText(list.get(position));
Button deleteBtn = (Button)view.findViewById(R.id.delete_btn);
Button addBtn = (Button)view.findViewById(R.id.add_btn);
myLayout=(LinearLayout)view.findViewById(R.id.lnear_momo);
addBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});
deleteBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});
return view;
}
}
the first xml layout is
<?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/list_item_string"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:paddingLeft="8dp"
android:textSize="18sp"
android:textStyle="bold" />
<Button
android:id="@+id/delete_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="5dp"
android:text="Delete" />
<Button
android:id="@+id/add_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@id/delete_btn"
android:layout_centerVertical="true"
android:layout_marginRight="10dp"
android:text="Add" />
</RelativeLayout>
and the second xml layout is
<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" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:background="#b2b3b7"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="com.efas.admin.efasrestaurant.Items_momo"
android:id="@+id/relate_momo">
<LinearLayout
android:orientation="vertical"
android:layout_width="500dp"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:id="@+id/linearLayout">
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/momo_list" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/linearLayout"
android:layout_toEndOf="@+id/linearLayout"
android:id="@+id/lnear_momo"></LinearLayout>
</RelativeLayout>
i want to add textview automatically as i click the add buttons in each row in listview in the LinearLayout whose id is lnear_momo and pass the text in that row of listview to that textview.

addView()to add dynamically.