Multiplechoice in AlertDialog - android

I use "lv_del_transl.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE)" to set this options.
code to create AlertDialog:
Al_tr.setTitle("Title");
RelativeLayout view_T = (RelativeLayout)getLayoutInflater().inflate(R.layout.listofword_cmenu_del_transl, null);
Al_tr.setView(view_T);
TextView del_transl = (TextView)view_T.findViewById(R.id.del_transl);
ListView lv_del_transl = (ListView)view_T.findViewById(R.id.lv_del_transl);
Button del_transl_OK = (Button)view_T.findViewById(R.id.del_transl_OK);
Button del_transl_Cancel = (Button)view_T.findViewById(R.id.del_transl_Cancel);
al_del_tr=Al_tr.create();
Del_transl.setText("word");
Cursor c_adap_tr=cur_del_tr(......);
startManagingCursor(c_adap_tr);
String[] from_r = new String[]{NAME};
int[] to_r = new int[] {R.id.transl };
scAdapter_transl = new SimpleCursorAdapter(this, R.layout.listofword_cmenu_del_transl_item, c_adap_tr, from_r, to_r);
lv_del_transl.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); // for set Multiple property
lv_del_transl.setAdapter(scAdapter_transl);
del_transl_OK.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
String sel="0";
SparseBooleanArray sbArray = lv_del_transl.getCheckedItemPositions();
for (int i = 0; i < lv_del_transl.getCount(); i++) {
if (sbArray.get(i))
sel+=Integer.toString(lv_del_transl.getCheckedItemPosition())+" ";
}
Toast.makeText(getApplicationContext(), Integer.toString(lv_del_transl.getCount())+" "+sel, Toast.LENGTH_SHORT).show();
}
});
al_del_rt.show();
Xml file for ListView
<LinearLayout
android:id="#+id/lv_del_translation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="5dp" >
<TextView
android:id="#+id/del_translation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="#string/text_del_translation"
android:textSize="20dp" />
<TextView
android:id="#+id/del_transl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="28dp"
android:text="#string/text_del_transl"
android:textSize="20dp" />
</LinearLayout>
<ListView
android:id="#+id/lv_del_transl"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/lv_del_translation"
android:layout_marginTop="10dp"
android:layout_weight="1"
android:choiceMode="multipleChoice" />
<LinearLayout
android:id="#+id/l_del_buttons"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_gravity="center"
android:background="#drawable/gradient_box"
android:orientation="horizontal"
android:padding="5dp" >
<Button
android:id="#+id/del_transl_OK"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/text_del_word_OK" />
<Button
android:id="#+id/del_transl_Cancel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/text_del_word_Cancel" />
</LinearLayout>
</RelativeLayout>
where listofword_cmenu_del_transl_item.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="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/transl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_centerVertical="true"
android:textSize="19sp">
</TextView>
<CheckBox
android:id="#+id/checbox_id"
android:layout_marginRight="10dp"
android:layout_alignParentRight="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</RelativeLayout>
But SparseBooleanArray sbArray has no effect. I can't define checked position. Please help me find a mistake.

private void showPopUp()
{
final AlertDialog.Builder helpBuilder = new AlertDialog.Builder(this);
helpBuilder.setTitle("");
LayoutInflater inflater = getLayoutInflater();
final View PopupLayout = inflater.inflate(R.layout.jobselection, null);
helpBuilder.setView(PopupLayout);
final AlertDialog helpDialog = helpBuilder.create();
helpDialog.show();
okbtn = (Button)PopupLayout.findViewById(R.id.okBtn);
caneclbtn = (Button)PopupLayout.findViewById(R.id.cancelBtn);
selectallbtn = (Button)PopupLayout.findViewById(R.id.selectBtn);
clearallbtn = (Button)PopupLayout.findViewById(R.id.clearallBtn);
jobList = (ListView)PopupLayout.findViewById(R.id.list);
mylist = new ArrayList<HashMap<String, String>>();
for(int i=0;i<Punchedjobs.size();i++)
{
map = new HashMap<String, String>();
map.put("name", Punchedjobs.get(i));
mylist.add(map);
}
sd = new SimpleAdapter(StaffTimeClock.this,mylist,R.layout.jobslist,
new String[]{"name"},new int[]{R.id.jobText});
jobList.setAdapter(sd);
okbtn.setOnClickListener(new OnClickListener() {
public void onClick(View v)
{
//ur code
}
});
caneclbtn.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
helpDialog.dismiss();
}
});
selectallbtn.setOnClickListener(new OnClickListener() {
public void onClick(View v)
{
CheckBox job_chk;
for(int i=0;i<Punchedjobs.size();i++)
{
job_chk= ((CheckBox)jobList.getChildAt(i).findViewById(R.id.chk));
job_chk.setChecked(true);
}
}
});
clearallbtn.setOnClickListener(new OnClickListener() {
public void onClick(View v)
{
CheckBox job_chk;
for(int i=0;i<Punchedjobs.size();i++)
{
job_chk= ((CheckBox)jobList.getChildAt(i).findViewById(R.id.chk));
job_chk.setChecked(false);
}
}
});
}
jobselection.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:orientation="vertical"
tools:context=".StaffTimeClock" >
<TextView
android:id="#+id/img"
android:layout_width="fill_parent"
android:text="#string/selectjob"
android:gravity="center"
android:textSize="30dp"
android:textColor="#fff"
android:background="#203C56"
android:padding="10dp"
android:layout_height="wrap_content"/>
<ListView
android:id="#+id/list"
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:cacheColorHint="#222000" />
<View
android:layout_width="fill_parent"
android:layout_height="3dp"
android:background="#000"/>
<LinearLayout android:id="#+id/lin00"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#fff"
android:orientation="horizontal">
<Button
android:layout_weight="0.1"
android:contentDescription="#string/ok"
android:id="#+id/okBtn"
android:layout_gravity="center"
android:layout_margin="10dp"
android:padding="10dp"
android:textSize="25dp"
android:background="#drawable/toolbar_background"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/ok"/>
<Button
android:layout_weight="0.1"
android:contentDescription="#string/ok"
android:id="#+id/selectBtn"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:padding="10dp"
android:textSize="25dp"
android:background="#drawable/toolbar_background"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/selectall"/>
<Button
android:layout_weight="0.1"
android:contentDescription="#string/ok"
android:id="#+id/clearallBtn"
android:layout_gravity="center"
android:layout_margin="10dp"
android:padding="10dp"
android:textSize="25dp"
android:background="#drawable/toolbar_background"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/clear"/>
<Button
android:layout_weight="0.1"
android:contentDescription="#string/cancel"
android:id="#+id/cancelBtn"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:padding="10dp"
android:textSize="25dp"
android:background="#drawable/toolbar_background"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/cancel"/>
</LinearLayout>
</LinearLayout>
jobslist.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/lin01"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#fff"
android:padding="10dp"
android:orientation="horizontal">
<ImageView
android:id="#+id/image"
android:contentDescription="#string/staff"
android:src="#drawable/logo2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:id="#+id/jobText"
android:layout_width="0dp"
android:text="#string/jobtype"
android:layout_weight="1"
android:gravity="left|center_vertical"
android:layout_marginLeft="10dp"
android:textSize="25dp"
android:textColor="#000"
android:layout_height="50dp"/>
<CheckBox
android:id="#+id/chk"
android:layout_width="wrap_content"
android:text=""
android:gravity="center_vertical|right"
android:button="#drawable/checkbox_selector_green"
android:layout_height="wrap_content"/>
</LinearLayout>

Related

How to click button inside listview

I know this problem already asked many times but i still can't get effective way for solving this. I try for use ListView with clickable/editable widget and Android : How to set onClick event for Button in List item of ListView as reference but the result is i need click button several time for executing my program. Here my program
LeadActivity.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".LeadSalesActivity">
<LinearLayout
android:background="#E9ECEB"
android:layout_margin="20dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/b_menusamping2"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_margin="20dp"
android:background="#drawable/menu_button"
android:backgroundTint="#27D01B"/>
</LinearLayout>
<LinearLayout
android:layout_marginTop="10dp"
android:layout_weight="1"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Welcome,"
android:textSize="20sp"
android:textStyle="italic"
android:textColor="#android:color/black"/>
<TextView
android:id="#+id/t_username3"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:text="Rizaldi"
android:textColor="#android:color/black"
android:textSize="25sp"
android:textStyle="bold"
android:fontFamily="#font/action_man_bold"/>
</LinearLayout>
<LinearLayout
android:id="#+id/linear_refresh2"
android:layout_margin="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#android:color/white">
<ImageView
android:backgroundTint="#27D01B"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_margin="10dp"
android:background="#drawable/icon_update"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_marginLeft="20dp"
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Lead"
android:textColor="#android:color/black"
android:textSize="20sp"/>
<TextView
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="("
android:textSize="20sp"
android:textColor="#android:color/black"/>
<TextView
android:textStyle="bold"
android:id="#+id/count_lead"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="100"
android:textColor="#android:color/black"
android:textSize="20sp"/>
<TextView
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text=")"
android:textSize="20sp"
android:textColor="#android:color/black"/>
<Button
android:id="#+id/btn_add"
android:layout_marginRight="20dp"
android:backgroundTint="#android:color/holo_blue_light"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tambah Lead"
android:textAllCaps="false"/>
</LinearLayout>
<LinearLayout
android:padding="20dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tanggal"
android:textColor="#android:color/black"
android:textSize="20sp"/>
<TextView
android:layout_marginLeft="30dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Lead"
android:textSize="20sp"
android:textColor="#android:color/black"/>
<TextView
android:layout_marginLeft="40dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Telp"
android:textColor="#android:color/black"
android:textSize="20sp"/>
</LinearLayout>
<ListView
android:id="#+id/listviewlead"
tools:listitem="#layout/c_lead"
android:layout_width="match_parent"
android:layout_height="400dp"
android:layout_weight="1" />
</LinearLayout>
</ScrollView>
</LinearLayout>
<LinearLayout
android:layout_marginTop="30dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<Button
android:id="#+id/back6"
android:layout_marginRight="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="back"/>
</LinearLayout>
c_lead.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="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/t_tgl"
android:focusable="false"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="8dp"
android:text="Tgl"
android:textSize="15sp"
android:textStyle="italic"
android:textColor="#000000" />
<TextView
android:id="#+id/t_lead4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="8dp"
android:text="Lead"
android:textSize="15sp"
android:textColor="#000000" />
<TextView
android:id="#+id/t_numberphone"
android:focusable="false"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="8dp"
android:gravity="right"
android:text="No.Telp"
android:textSize="15sp"
android:textColor="#android:color/black"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<LinearLayout
android:id="#+id/btn_edit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#drawable/kotak_abu"
android:layout_marginTop="5dp">
<ImageButton
android:layout_margin="10dp"
android:layout_width="30dp"
android:layout_height="30dp"
android:background="#drawable/pencil_icon"/>
</LinearLayout>
<LinearLayout
android:id="#+id/btn_delete"
android:layout_marginLeft="3dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#drawable/kotak_abu"
android:layout_marginRight="10dp"
android:layout_marginTop="5dp">
<ImageButton
android:layout_margin="10dp"
android:layout_width="30dp"
android:layout_height="30dp"
android:background="#drawable/delete_icon"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/t_alamat"
android:focusable="false"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="8dp"
android:text="Alamat"
android:textColor="#android:color/black"
android:textSize="15sp"
android:layout_marginLeft="20dp"/>
</LinearLayout>
MyAdapter
public View getView(final int _position, View _v, ViewGroup _container) {
LayoutInflater _inflater = (LayoutInflater)getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View _view = _v;
if (_view == null) {
_view = _inflater.inflate(R.layout.c_lead, null);
}
final HashMap<String, Object> hashMap = _data.get(_position);
final TextView t_tanggal = (TextView) _view.findViewById(R.id.t_tgl);
final TextView t_lead = (TextView) _view.findViewById(R.id.t_lead4);
final TextView t_alamat = (TextView) _view.findViewById(R.id.t_alamat);
final TextView t_numberphone = (TextView) _view.findViewById(R.id.t_numberphone);
final LinearLayout btn_edit = (LinearLayout) _view.findViewById(R.id.btn_edit);
final LinearLayout btn_delete = (LinearLayout) _view.findViewById(R.id.btn_delete);
String dateString = _data.get(_position).get("create_date").toString().replace("-","");
SimpleDateFormat format1 = new SimpleDateFormat("yyyyMMddHHmm");
format1.setTimeZone(TimeZone.getTimeZone("GMT+7"));
SimpleDateFormat format2 = new SimpleDateFormat("dd-MM-yyyy");
try {
Date date = format1.parse(dateString);
String dateFinal = format2.format(date);
t_tanggal.setText(String.valueOf((long)(_position + 1)).concat(".").concat(dateFinal));
} catch (ParseException e) {
e.printStackTrace();
}
t_lead.setText(_data.get((int)_position).get("type").toString());
t_alamat.setText(_data.get((int)_position).get("street").toString());
if (_data.get((int)_position).get("mobile").toString().equals(true)){
t_numberphone.setText("Tanpa Nomor");
} else {
t_numberphone.setText(_data.get((int)_position).get("phone").toString());
}
btn_edit.setFocusable(false);
btn_edit.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
i.setClass(getApplicationContext(), AddLeadSalesActivity.class);
startActivity(i);
}
});
btn_delete.setFocusable(false);
btn_delete.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Toast.makeText(getApplicationContext(), "Data Tidak Bisa Dihapus", Toast.LENGTH_SHORT).show();
}
});
return _view;
}
Is there any mistake inside my program? How to solve this?

NullPointerException on setContentView

I am having two layouts in same xml file and I have kept one layout as hidden and want to show this hidden layout on button click. But when I try to load this activity, it gives me exception on setContentView.
Here is my layout:
<androidx.drawerlayout.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/drawer1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#f0f5f9"
tools:context="com.techsof.demoapp.Auftrag">
<LinearLayout
android:id="#+id/header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="#drawable/round_corners"
android:orientation="vertical"
android:padding="10dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="serif"
android:gravity="center"
android:text="#string/heading"
android:textColor="#fff"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:fontFamily="serif"
android:gravity="center"
android:text="#string/heading_text"
android:textColor="#fff"
android:textSize="15sp" />
</LinearLayout>
<TextView
android:id="#+id/form_heading"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/header"
android:fontFamily="serif"
android:gravity="center"
android:text="#string/form_heading"
android:textColor="#4C4C4C"
android:textSize="20sp" />
<LinearLayout
android:id="#+id/form"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/form_heading"
android:layout_margin="10dp"
android:orientation="vertical">
<EditText
android:id="#+id/name"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#drawable/input_fields"
android:fontFamily="serif"
android:hint="#string/name"
android:padding="10dp" />
<EditText
android:id="#+id/mail"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="10dp"
android:background="#drawable/input_fields"
android:fontFamily="serif"
android:hint="#string/mail_"
android:padding="10dp" />
<EditText
android:id="#+id/tel"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="10dp"
android:background="#drawable/input_fields"
android:fontFamily="serif"
android:hint="Tel/Mobilnummer *"
android:padding="10dp" />
<EditText
android:id="#+id/aus"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="10dp"
android:background="#drawable/input_fields"
android:fontFamily="serif"
android:hint="Ausgangssprache *"
android:padding="10dp" />
<EditText
android:id="#+id/ziel"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="10dp"
android:background="#drawable/input_fields"
android:fontFamily="serif"
android:hint="Zielsprache *"
android:padding="10dp" />
<EditText
android:id="#+id/nach"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_marginTop="10dp"
android:background="#drawable/input_fields"
android:fontFamily="serif"
android:gravity="start"
android:hint="Nachricht *"
android:padding="10dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal">
<TextView
android:id="#+id/doc1"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_weight="1"
android:background="#drawable/odd_corners"
android:fontFamily="serif"
android:gravity="start"
android:padding="10dp" />
<Button
android:id="#+id/attach_btn1"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_weight="1.5"
android:background="#drawable/odd_corners_btn"
android:drawableStart="#drawable/ic_file_upload_black_24dp"
android:drawableLeft="#drawable/ic_file_upload_black_24dp"
android:text="#string/doc1"
android:textAllCaps="false"
android:textColor="#fff" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal">
<TextView
android:id="#+id/doc2"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_weight="1"
android:background="#drawable/odd_corners"
android:fontFamily="serif"
android:gravity="start"
android:padding="10dp" />
<Button
android:id="#+id/attach_btn2"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_weight="1.5"
android:background="#drawable/odd_corners_btn"
android:drawableStart="#drawable/ic_file_upload_black_24dp"
android:drawableLeft="#drawable/ic_file_upload_black_24dp"
android:text="#string/doc2"
android:textAllCaps="false"
android:textColor="#fff" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal">
<TextView
android:id="#+id/doc3"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_weight="1"
android:background="#drawable/odd_corners"
android:fontFamily="serif"
android:gravity="start"
android:padding="10dp" />
<Button
android:id="#+id/attach_btn3"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_weight="1.5"
android:background="#drawable/odd_corners_btn"
android:drawableStart="#drawable/ic_file_upload_black_24dp"
android:drawableLeft="#drawable/ic_file_upload_black_24dp"
android:text="#string/doc3"
android:textAllCaps="false"
android:textColor="#fff" />
</LinearLayout>
</LinearLayout>
<TextView
android:id="#+id/footer_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/form"
android:layout_margin="10dp"
android:fontFamily="serif"
android:gravity="center"
android:text="#string/footer_text"
android:textColor="#4C4C4C"
android:textSize="12sp"
android:textStyle="bold" />
<CheckBox
android:id="#+id/checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/footer_text"
android:layout_marginLeft="10dp"
android:buttonTint="#0F84AA"
android:fontFamily="serif"
android:text="#string/checkbox_text"
android:textColor="#4c4c4c"
android:textStyle="bold" />
<Button
android:id="#+id/sendBtn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/checkbox"
android:layout_margin="10dp"
android:background="#drawable/round_corners"
android:text="#string/button_text"
android:textAllCaps="false"
android:textColor="#fff" />
</RelativeLayout>
</ScrollView>
<LinearLayout
android:id="#+id/dialogBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:gravity="center"
android:orientation="vertical"
android:visibility="gone">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#4c4c4c"
android:padding="10dp"
android:text="#string/complete_action_using"
android:textColor="#fff"
android:textSize="20sp" />
<view
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#fff" />
<LinearLayout
android:id="#+id/cameraOption"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#CDCDCD"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="10dp"
android:src="#drawable/ic_camera_alt_black_24dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="#string/camera"
android:textColor="#fff"
android:textSize="18sp" />
</LinearLayout>
<view
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#fff" />
<LinearLayout
android:id="#+id/phoneStorageOption"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#CDCDCD"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="10dp"
android:src="#drawable/ic_folder_open_black_24dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="#string/phone_storage"
android:textColor="#fff"
android:textSize="18sp" />
</LinearLayout>
<view
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#fff" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#CDCDCD"
android:gravity="end"
android:padding="10dp">
<Button
android:id="#+id/cancelBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="10dp"
android:layout_marginRight="10dp"
android:backgroundTint="#0F84AA"
android:text="#string/cancel"
android:textColor="#fff" />
</LinearLayout>
</LinearLayout>
<com.google.android.material.navigation.NavigationView
android:id="#+id/navigation1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#f0f5f9"
app:headerLayout="#layout/nav_header"
app:itemIconTint="#000"
app:itemTextColor="#000"
app:menu="#menu/menu_main" />
</androidx.drawerlayout.widget.DrawerLayout>
and here is my Java Code:
public class Auftrag extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {
private DrawerLayout eDrawerlayout;
private ActionBarDrawerToggle eToggle;
NavigationView nav;
private LinearLayout camera, phone, dialog;
private Button attachBtn1, attachBtn2, attachBtn3, submitButton, cancel;
private TextView file1, file2, file3;
private EditText name, mail, telephone, ausgang, ziels, nachricht;
private ArrayList<Uri> attachments = new ArrayList<>();
private CheckBox agreement;
private String textfield;
public static final int REQUEST_SELECT_FILE = 100;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.form);
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
initUI();
eToggle = new ActionBarDrawerToggle(this, eDrawerlayout, R.string.Open, R.string.Close);
eDrawerlayout.addDrawerListener(eToggle);
eToggle.syncState();
nav.setNavigationItemSelectedListener(this);
androidx.appcompat.app.ActionBar actionBar = getSupportActionBar();
assert actionBar != null;
actionBar.setBackgroundDrawable(new ColorDrawable(android.graphics.Color.parseColor("#f0f5f9")));
eDrawerlayout.setDrawerListener(eToggle);
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayShowTitleEnabled(true);
}
private void initUI() {
nav = findViewById(R.id.navigation1);
eDrawerlayout = findViewById(R.id.drawer1);
name = findViewById(R.id.name);
mail = findViewById(R.id.mail);
telephone = findViewById(R.id.tel);
ausgang = findViewById(R.id.aus);
ziels = findViewById(R.id.ziel);
nachricht = findViewById(R.id.nach);
submitButton = findViewById(R.id.sendBtn);
attachBtn1 = findViewById(R.id.attach_btn1);
attachBtn2 = findViewById(R.id.attach_btn2);
attachBtn3 = findViewById(R.id.attach_btn3);
/*dialog = findViewById(R.id.dialogBox);
camera = findViewById(R.id.cameraOption);
camera.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
openCamera();
}
});
phone = findViewById(R.id.phoneStorageOption);
phone.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
openFileChooser();
}
});
cancel = findViewById(R.id.cancelBtn);
cancel.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
dialog.setVisibility(View.GONE);
}
});*/
file1 = findViewById(R.id.doc1);
file2 = findViewById(R.id.doc2);
file3 = findViewById(R.id.doc3);
attachBtn1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
textfield = "btn1";
chooseOption();
/*dialog.setVisibility(View.VISIBLE);*/
}
});
attachBtn2.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
textfield = "btn2";
/*dialog.setVisibility(View.VISIBLE);*/
}
});
attachBtn3.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
textfield = "btn3";
/*dialog.setVisibility(View.VISIBLE);*/
}
});
agreement = findViewById(R.id.checkbox);
submitButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
sendData();
}
});
}
private void chooseOption() {
final CharSequence[] options = {"Camera", "Phone", "Cancel"};
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Add file using: ");
builder.setItems(options, new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int item) {
if (options[item].equals("Camera")) {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File f = new File(android.os.Environment.getExternalStorageDirectory(), "temp.jpg");
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(f));
startActivityForResult(intent, 1);
} else if (options[item].equals("Phone")) {
openFileChooser();
} else if (options[item].equals("Cancel")) {
dialog.dismiss();
}
}
});
builder.show();
}
private void openFileChooser() {
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("*/*");
startActivityForResult(intent, REQUEST_SELECT_FILE);
}
private void sendData() {
if (TextUtils.isEmpty(name.getText()) || TextUtils.isEmpty(mail.getText()) ||
TextUtils.isEmpty(telephone.getText()) || TextUtils.isEmpty(ausgang.getText())
|| TextUtils.isEmpty(ziels.getText()) || TextUtils.isEmpty(nachricht.getText())
|| TextUtils.isEmpty(file1.getText()) || TextUtils.isEmpty(file3.getText()) ||
TextUtils.isEmpty(file3.getText())) {
Toast.makeText(this, "Please fill out all fields.", Toast.LENGTH_SHORT).show();
} else {
if (agreement.isChecked()) {
if (isConnected()) {
ArrayList<String> data = new ArrayList<>();
data.add(name.getText().toString());
data.add(mail.getText().toString());
data.add(telephone.getText().toString());
data.add(ausgang.getText().toString());
data.add(ziels.getText().toString());
data.add(nachricht.getText().toString());
new SendMailTask(this).execute("metaphrase.online#gmail.com", "Admintogether-2000222",
"salman.footy.k7#gmail.com", "User Information", data.get(0), data.get(1),
data.get(2), data.get(3), data.get(4), data.get(5), getFullPath(attachments.get(0)),
getFullPath(attachments.get(1)), getFullPath(attachments.get(2)));
} else {
Toast.makeText(this, "Please check your internet connection and try again.", Toast.LENGTH_SHORT).show();
}
} else {
Toast.makeText(this, "Please select the checkbox.", Toast.LENGTH_SHORT).show();
}
}
}
public boolean onOptionsItemSelected(#NonNull MenuItem item) {
if (eToggle.onOptionsItemSelected(item)) {
}
return true;
}
public boolean onNavigationItemSelected(#NonNull MenuItem item) {
int id = item.getItemId();
switch (id) {
case R.id.home:
startActivity(new Intent(Auftrag.this, MainActivity.class));
break;
case R.id.web:
Intent browser = new Intent(Intent.ACTION_VIEW, Uri.parse("https://metaphrase.online"));
startActivity(browser);
break;
case R.id.help:
startActivity(new Intent(Auftrag.this, Feedback.class));
break;
case R.id.upload:
if (isConnected()) {
startActivity(new Intent(Auftrag.this, Auftrag.class));
} else {
Toast.makeText(this, "Bitte überprüfen Sie Ihre Internetverbindung!", Toast.LENGTH_SHORT)
.show();
}
break;
}
eDrawerlayout.closeDrawer(GravityCompat.START);
return true;
}
#Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
if (requestCode != REQUEST_SELECT_FILE || resultCode != RESULT_OK) {
Toast.makeText(this, "No file selected.", Toast.LENGTH_SHORT).show();
dialog.setVisibility(View.GONE);
} else {
importFile(intent);
}
}
private void importFile(Intent intent) {
if (intent != null) {
String fileName = getFileName(intent.getData());
if (textfield != null) {
if (textfield.equals("btn1")) {
dialog.setVisibility(View.GONE);
file1.setText(fileName);
attachments.add(intent.getData());
} else if (textfield.equals("btn2")) {
dialog.setVisibility(View.GONE);
file2.setText(fileName);
attachments.add(intent.getData());
} else {
dialog.setVisibility(View.GONE);
file3.setText(fileName);
attachments.add(intent.getData());
}
} else {
Toast.makeText(this, "Try again later.", Toast.LENGTH_SHORT).show();
}
}
}
private String getFullPath(Uri fileUri) {
String filePath = null;
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
try {
filePath = PathUtil.getPath(this, fileUri);
} catch (URISyntaxException e) {
e.printStackTrace();
}
} else {
File file = new File(fileUri.getPath());
final String[] split = file.getPath().split(":");
filePath = split[1];
}
return filePath;
}
private String getFileName(Uri data) {
Cursor cursor = getContentResolver().query(data, null, null, null, null);
if (cursor.getCount() <= 0) {
cursor.close();
throw new IllegalArgumentException("Can't obtain file name, cursor is empty");
}
cursor.moveToFirst();
String fileName = cursor.getString(cursor.getColumnIndexOrThrow(OpenableColumns.DISPLAY_NAME));
cursor.close();
return fileName;
}
public boolean isConnected() {
boolean connected = false;
try {
ConnectivityManager cm = (ConnectivityManager) getApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo nInfo = cm.getActiveNetworkInfo();
connected = nInfo != null && nInfo.isAvailable() && nInfo.isConnected();
return connected;
} catch (Exception e) {
Log.e("Connectivity Exception", e.getMessage());
}
return connected;
}
}
So the problem should be in the <view ../> tag, the correct form is <View ... />. You should change your XML file with the following:
<androidx.drawerlayout.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/drawer1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#f0f5f9"
tools:context="com.techsof.demoapp.Auftrag">
<LinearLayout
android:id="#+id/header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="#drawable/round_corners"
android:orientation="vertical"
android:padding="10dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="serif"
android:gravity="center"
android:text="#string/heading"
android:textColor="#fff"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:fontFamily="serif"
android:gravity="center"
android:text="#string/heading_text"
android:textColor="#fff"
android:textSize="15sp" />
</LinearLayout>
<TextView
android:id="#+id/form_heading"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/header"
android:fontFamily="serif"
android:gravity="center"
android:text="#string/form_heading"
android:textColor="#4C4C4C"
android:textSize="20sp" />
<LinearLayout
android:id="#+id/form"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/form_heading"
android:layout_margin="10dp"
android:orientation="vertical">
<EditText
android:id="#+id/name"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#drawable/input_fields"
android:fontFamily="serif"
android:hint="#string/name"
android:padding="10dp" />
<EditText
android:id="#+id/mail"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="10dp"
android:background="#drawable/input_fields"
android:fontFamily="serif"
android:hint="#string/mail_"
android:padding="10dp" />
<EditText
android:id="#+id/tel"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="10dp"
android:background="#drawable/input_fields"
android:fontFamily="serif"
android:hint="Tel/Mobilnummer *"
android:padding="10dp" />
<EditText
android:id="#+id/aus"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="10dp"
android:background="#drawable/input_fields"
android:fontFamily="serif"
android:hint="Ausgangssprache *"
android:padding="10dp" />
<EditText
android:id="#+id/ziel"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="10dp"
android:background="#drawable/input_fields"
android:fontFamily="serif"
android:hint="Zielsprache *"
android:padding="10dp" />
<EditText
android:id="#+id/nach"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_marginTop="10dp"
android:background="#drawable/input_fields"
android:fontFamily="serif"
android:gravity="start"
android:hint="Nachricht *"
android:padding="10dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal">
<TextView
android:id="#+id/doc1"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_weight="1"
android:background="#drawable/odd_corners"
android:fontFamily="serif"
android:gravity="start"
android:padding="10dp" />
<Button
android:id="#+id/attach_btn1"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_weight="1.5"
android:background="#drawable/odd_corners_btn"
android:drawableStart="#drawable/ic_file_upload_black_24dp"
android:drawableLeft="#drawable/ic_file_upload_black_24dp"
android:text="#string/doc1"
android:textAllCaps="false"
android:textColor="#fff" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal">
<TextView
android:id="#+id/doc2"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_weight="1"
android:background="#drawable/odd_corners"
android:fontFamily="serif"
android:gravity="start"
android:padding="10dp" />
<Button
android:id="#+id/attach_btn2"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_weight="1.5"
android:background="#drawable/odd_corners_btn"
android:drawableStart="#drawable/ic_file_upload_black_24dp"
android:drawableLeft="#drawable/ic_file_upload_black_24dp"
android:text="#string/doc2"
android:textAllCaps="false"
android:textColor="#fff" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal">
<TextView
android:id="#+id/doc3"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_weight="1"
android:background="#drawable/odd_corners"
android:fontFamily="serif"
android:gravity="start"
android:padding="10dp" />
<Button
android:id="#+id/attach_btn3"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_weight="1.5"
android:background="#drawable/odd_corners_btn"
android:drawableStart="#drawable/ic_file_upload_black_24dp"
android:drawableLeft="#drawable/ic_file_upload_black_24dp"
android:text="#string/doc3"
android:textAllCaps="false"
android:textColor="#fff" />
</LinearLayout>
</LinearLayout>
<TextView
android:id="#+id/footer_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/form"
android:layout_margin="10dp"
android:fontFamily="serif"
android:gravity="center"
android:text="#string/footer_text"
android:textColor="#4C4C4C"
android:textSize="12sp"
android:textStyle="bold" />
<CheckBox
android:id="#+id/checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/footer_text"
android:layout_marginLeft="10dp"
android:buttonTint="#0F84AA"
android:fontFamily="serif"
android:text="#string/checkbox_text"
android:textColor="#4c4c4c"
android:textStyle="bold" />
<Button
android:id="#+id/sendBtn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/checkbox"
android:layout_margin="10dp"
android:background="#drawable/round_corners"
android:text="#string/button_text"
android:textAllCaps="false"
android:textColor="#fff" />
</RelativeLayout>
</ScrollView>
<LinearLayout
android:id="#+id/dialogBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:gravity="center"
android:orientation="vertical"
android:visibility="gone">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#4c4c4c"
android:padding="10dp"
android:text="#string/complete_action_using"
android:textColor="#fff"
android:textSize="20sp" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#fff" />
<LinearLayout
android:id="#+id/cameraOption"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#CDCDCD"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="10dp"
android:src="#drawable/ic_camera_alt_black_24dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="#string/camera"
android:textColor="#fff"
android:textSize="18sp" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#fff" />
<LinearLayout
android:id="#+id/phoneStorageOption"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#CDCDCD"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="10dp"
android:src="#drawable/ic_folder_open_black_24dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="#string/phone_storage"
android:textColor="#fff"
android:textSize="18sp" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#fff" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#CDCDCD"
android:gravity="end"
android:padding="10dp">
<Button
android:id="#+id/cancelBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="10dp"
android:layout_marginRight="10dp"
android:backgroundTint="#0F84AA"
android:text="#string/cancel"
android:textColor="#fff" />
</LinearLayout>
</LinearLayout>
<com.google.android.material.navigation.NavigationView
android:id="#+id/navigation1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#f0f5f9"
app:headerLayout="#layout/nav_header"
app:itemIconTint="#000"
app:itemTextColor="#000"
app:menu="#menu/menu_main" />
</androidx.drawerlayout.widget.DrawerLayout>

How to create custom dialog box with two button in android?

How to generate custom dialog box in android like this,
I want just like this.
How to generate it. please give me suggestion.
i have used below code for dialog box, what is the problem in my code?
I have not identify it. please share me any Idea.
<?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:background="#android:color/transparent">
<RelativeLayout
android:id="#+id/rl_quit_learning"
android:layout_width="match_parent"
android:layout_height="150dp"
android:background="#drawable/btn_white"
android:paddingBottom="#dimen/thirty_dp"
android:paddingLeft="#dimen/ten_dp"
android:paddingRight="#dimen/ten_dp"
android:paddingTop="#dimen/ten_dp">
<TextView
android:id="#+id/tv_quit_learning"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_margin="#dimen/ten_dp"
android:text="Quit LEarning?"
android:textSize="#dimen/twenty_sp"
android:textStyle="bold" />
<TextView
android:id="#+id/tv_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/tv_quit_learning"
android:layout_centerHorizontal="true"
android:layout_marginLeft="#dimen/ten_dp"
android:layout_marginRight="#dimen/ten_dp"
android:layout_marginTop="#dimen/twenty_dp"
android:gravity="center"
android:text="You are 400pts. away from \n unlocking rewards. Quit LEarning?"
android:textSize="#dimen/sixteen_sp" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="125dp"
android:gravity="center"
android:orientation="horizontal">
<Button
android:id="#+id/btn_cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cancel" />
<Button
android:id="#+id/btn_video"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Video" />
</LinearLayout>
</RelativeLayout>
Please share me any Idea.
Thanks.
Simple, 1st need to create an newcustom_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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:layout_width="match_parent"
android:layout_height="250dp"
android:layout_gravity="center"
android:layout_marginLeft="55dp"
android:layout_marginRight="55dp"
android:gravity="center">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:gravity="center_vertical"
android:orientation="vertical">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="165dp"
android:layout_gravity="center"
android:layout_marginEnd="60dp"
android:layout_marginStart="60dp"
app:cardCornerRadius="8dp"
app:cardElevation="15dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="14dp"
android:gravity="center"
android:text="Quit Earning?"
android:textColor="#android:color/black"
android:textSize="20dp"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginEnd="20dp"
android:layout_marginStart="20dp"
android:gravity="center"
android:text="You are 400pts. away from \n unlocking rewards. quit Earning?"
android:textSize="18dp"
android:textStyle="bold" />
</android.support.v7.widget.CardView>
</LinearLayout>
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:id="#+id/frmNo"
android:layout_marginRight="45dp"
android:layout_marginTop="75dp">
<android.support.design.widget.FloatingActionButton
android:layout_width="60dp"
android:layout_height="60dp"
android:src="#android:color/transparent"
app:backgroundTint="#color/fab2" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:elevation="6dp"
android:text="No"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#android:color/white"
android:textStyle="bold" />
</FrameLayout>
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:id="#+id/frmOk"
android:layout_marginLeft="50dp"
android:layout_marginTop="75dp">
<android.support.design.widget.FloatingActionButton
android:layout_width="60dp"
android:layout_height="60dp"
android:src="#android:color/transparent"
app:backgroundTint="#color/fab1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:elevation="6dp"
android:text="Ok"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#android:color/white"
android:textStyle="bold" />
</FrameLayout>
</FrameLayout>
Then, in java file (in activity) paste this code
public class ViewDialog {
public void showDialog(Activity activity) {
final Dialog dialog = new Dialog(activity);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setCancelable(false);
dialog.setContentView(R.layout.newcustom_layout);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
FrameLayout mDialogNo = dialog.findViewById(R.id.frmNo);
mDialogNo.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(),"Cancel" ,Toast.LENGTH_SHORT).show();
dialog.dismiss();
}
});
FrameLayout mDialogOk = dialog.findViewById(R.id.frmOk);
mDialogOk.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(),"Okay" ,Toast.LENGTH_SHORT).show();
dialog.cancel();
}
});
dialog.show();
}
}
Finally you can call it wherever you want.
ViewDialog alert = new ViewDialog();
alert.showDialog(CustomDialogActivity.this);
Inside your dailog.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:background="#android:color/white">
<RelativeLayout
android:id="#+id/rl_quit_learning"
android:layout_width="match_parent"
android:layout_height="150dp"
android:background="#drawable/btn_white"
android:paddingBottom="#dimen/thirty_dp"
android:paddingLeft="#dimen/ten_dp"
android:paddingRight="#dimen/ten_dp"
android:paddingTop="#dimen/ten_dp">
<TextView
android:id="#+id/tv_quit_learning"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_margin="#dimen/ten_dp"
android:text="Quit LEarning?"
android:textSize="#dimen/twenty_sp"
android:textStyle="bold" />
<TextView
android:id="#+id/tv_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/tv_quit_learning"
android:layout_centerHorizontal="true"
android:layout_marginLeft="#dimen/ten_dp"
android:layout_marginRight="#dimen/ten_dp"
android:layout_marginTop="#dimen/twenty_dp"
android:gravity="center"
android:text="You are 400pts. away from \n unlocking rewards. Quit LEarning?"
android:textSize="#dimen/sixteen_sp" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="125dp"
android:gravity="center"
android:orientation="horizontal">
<Button
android:id="#+id/btn_cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#mipmap/ic_launcher" />
<Button
android:id="#+id/btn_video"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#mipmap/ic_launcher" />
</LinearLayout>
</RelativeLayout>
open dimens.xml and add code mentioned below
<dimen name="thirty_dp">30dp</dimen>
<dimen name="ten_dp">10dp</dimen>
<dimen name="twenty_sp">20sp</dimen>
<dimen name="twenty_dp">20dp</dimen>
<dimen name="sixteen_sp">16sp</dimen>
open drawable and create btn_white.xml add code mentioned blow
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:radius="2dp"></corners>
<solid android:color="#android:color/white"></solid>
</shape>
open mainactivity.java and add the code mentioned below
final Dialog dialog = new Dialog(MainActivity.this);
// Include dialog.xml file
dialog.setContentView(R.layout.dailog);
dialog.show();
Button declineButton = (Button) dialog.findViewById(R.id.btn_cancel);
// if decline button is clicked, close the custom dialog
declineButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// Close dialog
dialog.dismiss();
}
});
Button videoButton = (Button) dialog.findViewById(R.id.btn_video);
// if decline button is clicked, close the custom dialog
videoButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
}
});
custom_dialog.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="80dp"
android:background="#3E80B4"
android:orientation="vertical" >
<TextView
android:id="#+id/txt_dia"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="10dp"
android:text="Do you realy want to exit ?"
android:textColor="#android:color/white"
android:textSize="15dp"
android:textStyle="bold"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#3E80B4"
android:orientation="horizontal" >
<Button
android:id="#+id/btn_yes"
android:layout_width="100dp"
android:layout_height="30dp"
android:background="#android:color/white"
android:clickable="true"
android:text="Yes"
android:textColor="#5DBCD2"
android:textStyle="bold" />
<Button
android:id="#+id/btn_no"
android:layout_width="100dp"
android:layout_height="30dp"
android:layout_marginLeft="5dp"
android:background="#android:color/white"
android:clickable="true"
android:text="No"
android:textColor="#5DBCD2"
android:textStyle="bold" />
</LinearLayout>
You can change your button by using
android:src=#drawable/image
You have to extends Dialog and implements OnClickListener
public class CustomDialogClass extends Dialog implements
android.view.View.OnClickListener {
public Activity c;
public Dialog d;
public Button yes, no;
public CustomDialogClass(Activity a) {
super(a);
// TODO Auto-generated constructor stub
this.c = a;
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.custom_dialog);
yes = (Button) findViewById(R.id.btn_yes);
no = (Button) findViewById(R.id.btn_no);
yes.setOnClickListener(this);
no.setOnClickListener(this);
}
#Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btn_yes:
c.finish();
break;
case R.id.btn_no:
dismiss();
break;
default:
break;
}
dismiss();
}
}
Call Dialog
CustomDialogClass cdd=new CustomDialogClass(Activity.this);
cdd.show();
Maybe try this method
dialog.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
app:cardBackgroundColor="#color/colorPrimary"
app:cardCornerRadius="16dp"
app:cardElevation="10dp"
app:contentPadding="20dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_done_all"
android:layout_gravity="center_horizontal"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/colorButtonNormal"
android:text="Tebrikler!"
android:layout_gravity="center_horizontal"
android:textSize="36sp"
android:padding="8dp"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="#+id/btnDialogCancel"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:text="Çıkış"
android:textColor="#FFF"
android:layout_marginRight="5dp"
android:background="#drawable/dialog_button_background"
android:layout_gravity="center_horizontal"/>
<Button
android:id="#+id/btnDialogOk"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:text="Devam"
android:textColor="#FFF"
android:layout_marginLeft="5dp"
android:background="#drawable/dialog_button_background"
android:layout_gravity="center_horizontal"/>
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
main.java
Dialog dialog = new Dialog(context, R.style.CustomDialog);
LayoutInflater layoutInflater = LayoutInflater.from(context);
CardView cardView = (CardView) layoutInflater.inflate(R.layout.dialog, null);
dialog.setContentView(cardView);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
dialog.show();
dialogBtnCancel();
private void dialogBtnCancel(){
mBtnDialogCancel = dialog.findViewById(R.id.btnDialogCancel);
mBtnDialogOk = dialog.findViewById(R.id.btnDialogOk);
mBtnDialogCancel.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
dialog.dismiss();
}
});
mBtnDialogOk.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent = new Intent(getActivity(), MainActivity.class);
startActivity(intent);
}
});
}

What's the difference between listview item and listview footer in rendering life cycle?

I have a listview contains items and footer views. Items layout works as it should, but footer's layout doesn't work like item views...
I could't understand where my fault is.
This is my item's layout 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:gravity="center"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/lstCardItem"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:background="#drawable/pm_dashboard_cardshadow" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5.33dp"
android:layout_marginLeft="11.67dp"
android:layout_marginRight="11.67dp"
android:layout_marginTop="6dp" >
<ImageView
android:id="#+id/ivCard"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:animateLayoutChanges="true"
android:scaleType="fitXY" />
<com.controls.DynamicResizeImageView
android:id="#+id/ivCardLock"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:animateLayoutChanges="true"
android:background="#drawable/pm_dashboard_cardmask"
android:scaleType="center"
android:src="#drawable/selector_btn_dashboard_lock" />
<LinearLayout
android:id="#+id/llInfo"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:gravity="top|right"
android:orientation="vertical"
android:paddingLeft="18dp"
android:paddingRight="18dp"
android:visibility="visible" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center|right"
android:gravity="center|right"
android:orientation="horizontal"
android:paddingBottom="4dp"
android:paddingTop="4dp" >
<TextView
android:id="#+id/tvCardBalance"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="#+id/tvCurrency"
android:gravity="top"
android:text="10,344"
android:textColor="#color/white"
android:textSize="18dp"
android:typeface="serif" />
<TextView
android:id="#+id/tvCurrency"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginLeft="3dp"
android:layout_marginTop="2dp"
android:gravity="top"
android:text="#string/global_currency"
android:textColor="#color/white"
android:textSize="10dp"
android:typeface="sans" />
<TextView
android:id="#+id/tvCardBalanceName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:text="#string/pgDashboard_lblBalanceBanner"
android:textColor="#color/white"
android:textSize="11.33dp"
android:typeface="monospace" />
</RelativeLayout>
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/pm_dashboard_seam" />
</LinearLayout>
For my businness side lifecycle:
private void refreshCards() {
if (applyButtons != null)
DashboardFragment.this.lvCards.removeFooterView(applyButtons);
applyButtons = new LinearLayout(getActivity());
applyButtons.setTag("FOOTER");
applyButtons.setOrientation(LinearLayout.VERTICAL);
AbsListView.LayoutParams LLParams = new AbsListView.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
applyButtons.setLayoutParams(LLParams);
if (ininalCount < 32) {
View createNewCardButton = getApplyButtonView(R.string.pgDashboard_lblCreateIninalCard, R.drawable.pm_dashboard_card_yenikartolustur, R.drawable.pm_dashboard_arrow_icon, new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(getActivity(), CreateNewCardActivity.class);
startActivity(intent);
}
});
View AddCard = getApplyButtonView(R.string.pgDashboard_lblAddCard, R.drawable.pm_dashboard_card_yenikartekle, R.drawable.pm_dashboard_plus_icon, new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(getActivity(), AddCardActivity.class);
startActivity(intent);
}
});
applyButtons.addView(createNewCardButton);
applyButtons.addView(AddCard);
}
final View applyIngCard = getApplyButtonView(R.string.pgDashboard_lblApplyToIngCard, R.drawable.pm_dashboard_card_orange, R.drawable.pm_dashboard_arrow_icon, new View.OnClickListener() {
#Override
public void onClick(View v) {
CardApplicationActivity.Synchronizer.synchronize((BaseActivity) getActivity(), new OnSyncCompletedListener() {
#Override
public void onSyncCompleted() {
Intent intent = new Intent(getActivity(), CardApplicationActivity.class);
startActivity(intent);
}
});
}
});
applyButtons.addView(applyIngCard);
View view = new View(getActivity());
view.setLayoutParams(new AbsListView.LayoutParams(AbsListView.LayoutParams.MATCH_PARENT, (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 20, getResources().getDisplayMetrics())));
view.setBackgroundResource(getResources().getColor(R.color.transparent));
applyButtons.addView(view);
bindAdapter();
}
private View getApplyButtonView(int stringId, int backgroundId, int iconId, View.OnClickListener onClickListener) {
final View view = inflater.inflate(R.layout.dashboard_list_card_item, null);
return view;
}
public void bindAdapter() {
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
DashboardFragment.this.lvCards.setLayoutTransition(new LayoutTransition());
DashboardFragment.this.lvCards.addFooterView(applyButtons, null, false);
if (adapter == null) {
adapter = new CardListAdapter(getActivity(), R.layout.dashboard_list_card_item, productModelContainerList);
controller = new CardListController(lvCards);
lvCards.setDropListener(this);
controller.setDragInitMode(CardListController.ON_LONG_PRESS);
lvCards.setFloatViewManager(controller);
lvCards.setOnTouchListener(controller);
lvCards.setAdapter(adapter);
}
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
DashboardFragment.this.lvCards.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
DashboardFragment.this.lvCards.setLayoutTransition(null);
}
}
Here i made some changes,, use these and let me know... otherwise i need your drawable resources to set this.
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/lstCardItem"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:background="#color/background_holo_dark" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5.33dp"
android:layout_marginLeft="11.67dp"
android:layout_marginRight="11.67dp"
android:layout_marginTop="6dp" >
<ImageView
android:id="#+id/ivCard"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:animateLayoutChanges="true"
android:scaleType="fitXY" />
<ImageView
android:id="#+id/ivCardLock"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:animateLayoutChanges="true"
android:background="#color/background_holo_light"
android:scaleType="center"
android:src="#color/bgColor" />
<LinearLayout
android:id="#+id/llInfo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/cropBG"
android:gravity="top|right"
android:orientation="vertical"
android:paddingLeft="18dp"
android:paddingRight="18dp"
android:visibility="visible" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="right|center_horizontal"
android:gravity="center|right"
android:orientation="horizontal"
android:paddingBottom="4dp"
android:paddingTop="4dp" >
<TextView
android:id="#+id/tvCardBalance"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="#+id/tvCurrency"
android:gravity="top"
android:text="10,344"
android:textColor="#android:color/white"
android:textSize="18dp"
android:typeface="serif" />
<TextView
android:id="#+id/tvCurrency"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginLeft="3dp"
android:layout_marginTop="2dp"
android:gravity="top"
android:text="Currency"
android:textColor="#android:color/white"
android:textSize="10dp"
android:typeface="sans" />
<TextView
android:id="#+id/tvCardBalanceName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="pgDashboard_lblBalanceBanner"
android:textColor="#android:color/white"
android:textSize="11.33dp"
android:typeface="monospace" />
</RelativeLayout>
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/bottom_btn_bg_color" />
</LinearLayout>

ImageView and textView getting overlapped when trying to inflate xml

I have an xml which contain imageview and textview.Textview is placed toRightOf ImageView , but when i try to inflate the xml imageView and textview is getting overlapped.Any help is appreciated
data.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" >
<ImageView
android:id="#+id/img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:paddingBottom="5dp"
android:src="#drawable/payback" />
<TextView
android:id="#+id/txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_toRightOf="#+id/img"
android:paddingTop="5dp"
android:text="33%" />
<TextView
android:id="#+id/header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/img"
android:paddingBottom="10dp"
android:text="Important and Urgent" />
</RelativeLayout>
Activity Code
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.check);
content=(LinearLayout)findViewById(R.id.content);
today=(TextView)findViewById(R.id.today);
tomorrow=(TextView)findViewById(R.id.tomorrow);
today.setOnClickListener(new TextView.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
//Toast.makeText(ToDo.this, "Before"+content.getChildCount(), Toast.LENGTH_LONG).show();
content.removeAllViews();
inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
int id=0;
for (int idx = 0; idx < 4; idx++) {
id = idx + 1;
rel = (RelativeLayout) inflater.inflate(R.layout.data, null);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
params.setMargins(0, 50, 0, 0);
txt = (TextView) rel.findViewById(R.id.txt);
txt.setText("AAA"+idx);
img = (ImageView) rel.findViewById(R.id.img);
img.setImageResource(R.drawable.payback);
img.setId(id);
content.addView(rel, params);
}
content.setVisibility(View.VISIBLE);
}
});
}
check.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:orientation="vertical" >
<RelativeLayout
android:id="#+id/whiteboard"
android:layout_width="250dp"
android:layout_height="300dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="60dp"
android:background="#FFFFFF" >
<Button
android:id="#+id/add"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_marginBottom="17dp"
android:layout_marginLeft="20dp"
android:text="Add" />
<View
android:id="#+id/bottomseperator"
android:layout_width="200dp"
android:layout_height="1dp"
android:layout_above="#+id/add"
android:layout_alignLeft="#+id/add"
android:layout_marginBottom="10dp"
android:background="#000000" />
<View
android:id="#+id/topseperator"
android:layout_width="220dp"
android:layout_height="1dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="35dp"
android:background="#000000" />
<TextView
android:id="#+id/day"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="20dp"
android:layout_marginTop="8dp"
android:text="Day :"
android:textSize="15sp" />
<TextView
android:id="#+id/today"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/day"
android:layout_alignBottom="#+id/day"
android:layout_toRightOf="#+id/day"
android:text="Today /"
android:textSize="15sp" />
<TextView
android:id="#+id/tomorrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/today"
android:layout_alignBottom="#+id/today"
android:layout_toRightOf="#+id/today"
android:text="Tomorrow /"
android:textSize="15sp" />
<TextView
android:id="#+id/custom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/tomorrow"
android:layout_alignBottom="#+id/tomorrow"
android:layout_toRightOf="#+id/tomorrow"
android:text="Custom"
android:textSize="15sp" />
<ScrollView
android:id="#+id/contenntscroll"
android:layout_width="200dip"
android:layout_height="200dip"
android:layout_alignBottom="#+id/whiteboard"
android:layout_alignTop="#+id/whiteboard"
android:layout_below="#+id/topseperator"
android:layout_marginLeft="20dp"
android:layout_marginTop="10dp"
android:isScrollContainer="false"
android:scrollbars="none" >
<LinearLayout
android:id="#+id/content"
android:layout_width="200dp"
android:layout_height="300dp"
android:layout_marginTop="30dp"
android:orientation="vertical" >
</LinearLayout>
</ScrollView>
</RelativeLayout>
</RelativeLayout>
The statement:
img.setId(id);
is causing the problem remove this statement the code would work.

Categories

Resources