how can i make my alert dialog box in android - android

I want to make my alert dialog box something like this.This is a popup window where you have to choose and select the category.Its coming when I click any listview item..
But I ended up make it something like this.as i am a newbie so don't know much about designing.kindly help me in this.
my xml layout:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:background="#FFFFFF"
android:gravity="start"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical" >
<ImageView
android:id="#+id/desimage"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_marginLeft="5dp"
android:layout_marginRight="2dp"
android:layout_marginTop="10dp"
android:src="#drawable/logo" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
android:layout_weight="1" >
<TextView
android:text="Chicken Pizza Small"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="21sp"
android:textStyle="bold"
android:id="#+id/h1"
android:layout_weight="1" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
android:layout_weight="1" >
<TextView
android:text="Chicken Pizza Small Combo"
android:layout_width="wrap_content"
android:textSize="16sp"
android:layout_height="wrap_content"
android:textColor="#8c8181"
android:id="#+id/h2"
android:layout_weight="1" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
android:layout_weight="1" >
<Button
android:text="Quantity"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/mybutton"
android:textColor="#ffffff"
android:id="#+id/quant"
android:layout_weight="1" />
<Button
android:text="-"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/incr"
android:textSize="10sp"
android:textColor="#color/colorButton"
android:layout_weight="1" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number"
android:layout_weight="1"
android:id="#+id/n1"
/>
<Button
android:text="+"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="10sp"
android:textColor="#color/colorButton"
android:layout_weight="1" />
android:id="#+id/decr"
android:layout_weight="1" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
android:layout_weight="1" >
<CheckBox
android:text="SL"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/sl"
android:textColor="#8c8181"
android:layout_weight="1" />
<CheckBox
android:text="S"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/s"
android:textColor="#8c8181"
android:layout_weight="1" />
<CheckBox
android:text="M"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/m"
android:textColor="#8c8181"
android:layout_weight="1" />
<CheckBox
android:text="l"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/L"
android:textColor="#8c8181"
android:layout_weight="1" />
<CheckBox
android:text="F"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/f"
android:textColor="#8c8181"
android:layout_weight="1" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
android:layout_weight="1" >
<View
android:layout_width="fill_parent"
android:layout_height="2dp"
android:background="#c0c0c0"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
android:layout_weight="1" >
<Spinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/spinner1"
android:background="#drawable/spinner_bg"
android:layout_weight="1" />
<Spinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/spinner2"
android:background="#drawable/spinner_bg"
android:layout_weight="1" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
android:layout_weight="1" >
<TextView
android:text="TextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView2"
android:layout_weight="1" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
android:layout_weight="1" >
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="hint" />
</android.support.design.widget.TextInputLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
android:layout_weight="1" >
<Button
android:text="Cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/canc"
android:textColor="#ffffff"
android:background="#drawable/mybutton2"
android:layout_weight=".5" />
<Button
android:text="Ok"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/ok"
android:textColor="#ffffff"
android:background="#drawable/mybutton"
android:layout_weight=".5" />
</LinearLayout>
</LinearLayout>
</ScrollView>
here is my SubMenu Activity where if u click an item it will show popup
public class SubMenu extends AppCompatActivity {
JSONObject jsonobject;
JSONArray jsonarray;
ListView listview;
ListViewAdapter adapter;
ProgressDialog mProgressDialog;
ArrayList<HashMap<String, String>> arraylist;
static String RANK = "id";
static String COUNTRY = "name";
static String FLAG = "image";
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sub_menu);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
String SelectedId = getIntent().getStringExtra("id");
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
// Get the view from listview_main.xml
// Execute DownloadJSON AsyncTask
new DownloadJSON().execute();
}
// DownloadJSON AsyncTask
private class DownloadJSON extends AsyncTask<Void, Void, Void> implements AdapterView.OnItemClickListener {
// #Override
// protected void onPreExecute() {
// super.onPreExecute();
// Create a progressdialog
// mProgressDialog = new ProgressDialog(SubMenu.this);
// Set progressdialog title
// mProgressDialog.setTitle("Categories of Main categories.....");
// Set progressdialog message
// mProgressDialog.setMessage("Loading...");
// mProgressDialog.setIndeterminate(false);
// Show progressdialog
// mProgressDialog.show();
// }
#Override
protected Void doInBackground(Void... params) {
// Create an array
arraylist = new ArrayList<HashMap<String, String>>();
// Retrieve JSON Objects from the given URL address
jsonarray = JsonFunctions
.getJSONfromURL("http://cloud.granddubai.com/broccoli/menu_typeitem.php?id=" + getIntent().getStringExtra("id"));
try {
// Locate the array name in JSON
// jsonarray = jsonobject.getJSONArray("main_menu_items");
for (int i = 0; i < jsonarray.length(); i++) {
HashMap<String, String> map = new HashMap<String, String>();
jsonobject = jsonarray.getJSONObject(i);
// Retrive JSON Objects
// map.put("id", jsonobject.getString("id"));
map.put("name", jsonobject.getString("name"));
map.put("image", jsonobject.getString("image"));
// Set the JSON Objects into the array
arraylist.add(map);
}
} catch (JSONException e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
return null;
}
#Override
protected void onPostExecute(Void args) {
// Locate the listview in listview_main.xml
listview = (ListView) findViewById(R.id.list1);
// Pass the results into ListViewAdapter.java
adapter = new ListViewAdapter(SubMenu.this, arraylist);
// Set the adapter to the ListView
listview.setAdapter(adapter);
listview.setOnItemClickListener(this);
// Close the progressdialog
// mProgressDialog.dismiss();
}
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
LayoutInflater layoutInflater
= (LayoutInflater)getBaseContext()
.getSystemService(LAYOUT_INFLATER_SERVICE);
View popupView = layoutInflater.inflate(R.layout.popup, null);
final PopupWindow popupWindow = new PopupWindow(
popupView,
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
Button btnDismiss = (Button)popupView.findViewById(R.id.canc);
btnDismiss.setOnClickListener(new Button.OnClickListener(){
#Override
public void onClick(View v) {
popupWindow.dismiss();
}});
popupWindow.showAsDropDown(view, 3000, -90);
}
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
onBackPressed();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
}

Replace your layout xml file with this:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="10dp">
<ImageView
android:id="#+id/desimage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:src="#drawable/logo" />
<TextView
android:id="#+id/h1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="Chicken Pizza Small"
android:textSize="21sp"
android:textStyle="bold" />
<TextView
android:id="#+id/h2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="Chicken Pizza Small Combo"
android:textColor="#8c8181"
android:textSize="16sp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginTop="10dp"
android:orientation="horizontal"
android:weightSum="10">
<Button
android:id="#+id/quant"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginRight="10dp"
android:layout_weight="3"
android:background="#drawable/mybutton"
android:text="Quantity"
android:textAllCaps="false"
android:textColor="#ffffff" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_weight="7"
android:background="#drawable/stroke_button"
android:orientation="horizontal"
android:weightSum="3">
<Button
android:id="#+id/incr"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#android:color/transparent"
android:text="-"
android:textColor="#FFA726"
android:textSize="25dp" />
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#c0c0c0" />
<EditText
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:inputType="number"
android:text="5" />
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#c0c0c0" />
<Button
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#android:color/transparent"
android:text="+"
android:textColor="#FFA726"
android:textSize="25dp" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp">
<CheckBox
android:id="#+id/sl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:buttonTint="#c0c0c0"
android:text="SL"
android:textColor="#8c8181"
tools:targetApi="lollipop" />
<CheckBox
android:id="#+id/s"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:buttonTint="#c0c0c0"
android:text="S"
android:textColor="#8c8181"
tools:targetApi="lollipop" />
<CheckBox
android:id="#+id/m"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:buttonTint="#c0c0c0"
android:text="M"
android:textColor="#8c8181"
tools:targetApi="lollipop" />
<CheckBox
android:id="#+id/L"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:buttonTint="#c0c0c0"
android:text="l"
android:textColor="#8c8181"
tools:targetApi="lollipop" />
<CheckBox
android:id="#+id/f"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:buttonTint="#c0c0c0"
android:text="F"
android:textColor="#8c8181"
tools:targetApi="lollipop" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:background="#c0c0c0" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginRight="10dp"
android:layout_weight="1"
android:background="#drawable/stroke_button"
android:orientation="vertical"
android:paddingBottom="5dp"
android:paddingTop="5dp">
<Spinner
android:id="#+id/spinner1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="5dp" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:layout_weight="1"
android:background="#drawable/stroke_button"
android:orientation="vertical"
android:paddingBottom="5dp"
android:paddingTop="5dp">
<Spinner
android:id="#+id/spinner2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="5dp" />
</LinearLayout>
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="SPECIAL INSTRUCTIONS"
android:textSize="16sp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="150dp"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:background="#drawable/stroke_button"
android:padding="#dimen/_10sdp">
<EditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/transparent"
android:gravity="top"
android:inputType="textCapSentences|textMultiLine"
android:lines="5"
android:maxLines="5"
android:padding="2dp"
android:textColor="#c0c0c0" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp">
<Button
android:id="#+id/canc"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:layout_weight="1"
android:background="#drawable/mybutton2"
android:text="Cancel"
android:textColor="#ffffff" />
<Button
android:id="#+id/ok"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_weight="1"
android:background="#drawable/mybutton"
android:text="Ok"
android:textColor="#ffffff" />
</LinearLayout>
</LinearLayout>
</ScrollView>
In your res/drawable add these xml:
mybutton.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="25dp" />
<solid android:color="#004D40" />
</shape>
mybutton2.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="25dp" />
<solid android:color="#FFA726" />
</shape>
stroke_button.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#FFFFFF" />
<corners android:radius="20dp" />
<stroke
android:width="1dp"
android:color="#c0c0c0" />
</shape>

#z.al
1) For set quantity u remove two button instead of two button you simply put two TextView so now you have Total 3 TextView (One for "-" one for "Count" and one for "+"). This Textview have Linear as parent and with the help of Drawable XML u can set Background.
2) And for Spinner you need to implement Custom Spinner
for Proper view give proper padding and margin.
refer link for custom spinner: "http://mrbool.com/how-to-customize-spinner-in-android/28286"

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 in dialog - Strange case

I have a stupid problem but i couldnt solve it yet. I have an activity with a button in toolbar, this button open one dialog with some filter params.
Here is what a i did..
Spinner spinner_categoria;
Spinner spinner_vendedor;
SeekBar seek_preco;
TextView tv_filtro;
onCreate method {
...
}
onClickEvent{
dialogFiltro();
}
public void dialogFiltro() {
Context context = SalesActivity.this;
final Dialog dialog;
dialog = new Dialog(context);
//dialog.setContentView(R.layout.dialog_filtro);
// dialog.setTitle("Filtro");
//dialog.show();
VendedorDAO auxVendedor = new VendedorDAO();
final List<String> listVendedor = auxVendedor.getVendedorList();
View dialogView = LayoutInflater.from(context).inflate(R.layout.dialog_filtro, null, false);
CardView bt_cancelar = (CardView) dialogView.findViewById(R.id.cb_filtro_cancelar);
CardView bt_aceitar = (CardView) dialogView.findViewById(R.id.cb_filtro_aceitar);
seek_preco = (SeekBar) dialogView.findViewById(R.id.sb_preco_max);
tv_filtro = (TextView) dialogView.findViewById(R.id.tv_filtro_preco);
spinner_categoria = (Spinner) dialogView.findViewById(R.id.spinner_categoria);
spinner_vendedor = (Spinner) dialogView.findViewById(R.id.spinner_vendedor);
spinner_categoria.setAdapter(ArrayAdapter.createFromResource(
this, R.array.categoria_array, android.R.layout.simple_spinner_item));
spinner_vendedor.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, listVendedor));
String oi = "oi";
tv_filtro.setText(oi);
dialog.setContentView(dialogView);
dialog.show();
seek_preco.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
#Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
// tv_filtro.setText("R$ " + progress);
// Log.i("RS " , String.valueOf(progress));
}
#Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
#Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
bt_cancelar.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
dialog.dismiss();
}
});
bt_aceitar.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
categoria = (String) spinner_categoria.getSelectedItem();
vendedor = (Integer) spinner_vendedor.getFirstVisiblePosition();
Log.e("id vendedor ", String.valueOf(vendedor));
if (vendedor == 0) {
vendedor = -1;
}
int precoAux = seek_preco.getProgress();
precoMax = (float) precoAux;
}
});
}
I have this in dialog_filtro.xml file:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:cardview="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="#+id/card"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_margin="8dp"
android:foreground="#drawable/border_card"
card_view:cardElevation="2dp"
card_view:cardMaxElevation="8dp">
<ScrollView
android:id="#+id/scrollView2"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:orientation="vertical">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="#+id/cb_filtro_cancelar"
android:layout_width="70dp"
android:layout_height="30dp"
android:background="#color/colorPrimary"
android:elevation="2dp"
android:text="X"
android:textColor="#android:color/white" />
<Button
android:id="#+id/cb_filtro_aceitar"
android:layout_width="70dp"
android:layout_height="30dp"
android:layout_gravity="end"
android:background="#color/colorPrimary"
android:elevation="2dp"
android:text="Aceitar"
android:textColor="#android:color/white" />
</FrameLayout>
<TextView
android:id="#+id/textView9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="5dp"
android:text="Filtrar por"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#color/colorPrimary" />
<TextView
android:id="#+id/tv_label_categoria"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_weight="1"
android:gravity="center"
android:text="Categoria"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Spinner
android:id="#+id/spinner_categoria"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:spinnerMode="dialog" />
<TextView
android:id="#+id/tv_label_vendedor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_weight="1"
android:gravity="center"
android:text="Supermercado"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Spinner
android:id="#+id/spinner_vendedor"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:spinnerMode="dialog" />
<TextView
android:id="#+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Preço máximo"
android:textAppearance="?android:attr/textAppearanceMedium" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal">
<SeekBar
android:id="#+id/sb_preco_max"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:indeterminate="false"
android:max="100"
android:progress="0" />
<TextView
android:id="#+id/tv_filtro_preco"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:text="5"
android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout>
<View
android:id="#+id/rv_shoppingcart_separator"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginBottom="2dp"
android:layout_marginTop="10dp"
android:background="#android:color/darker_gray" />
<TextView
android:id="#+id/tv_label_oerdenar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="15dp"
android:text="Ordenar por"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#color/colorPrimary" />
<TextView
android:id="#+id/textView11"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Preço:"
android:textAppearance="?android:attr/textAppearanceMedium" />
<RadioGroup
android:id="#+id/group_preco"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_marginLeft="5dp"
android:layout_marginTop="10dp"
android:gravity="center"
android:orientation="horizontal">
<RadioButton
android:id="#+id/rb_preco_maior"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:checked="false"
android:text="Maior" />
<RadioButton
android:id="#+id/rb_preco_menor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:checked="false"
android:text="Menor" />
</RadioGroup>
<TextView
android:id="#+id/tv_label_data_Validade"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:layout_weight="1"
android:text="Data de validade:"
android:textAppearance="?android:attr/textAppearanceMedium" />
<RadioGroup
android:id="#+id/group_validade"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:layout_weight="1"
android:gravity="center"
android:orientation="horizontal">
<RadioButton
android:id="#+id/rb_validade_maior"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:checked="false"
android:text="Maior" />
<RadioButton
android:id="#+id/rb_validade_menor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:checked="false"
android:text="Menor" />
</RadioGroup>
<LinearLayout
android:id="#+id/linear_isoffer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="#+id/tv_label_ofertas"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_weight="1"
android:text="Apenas ofertas:"
android:textAppearance="?android:attr/textAppearanceMedium" />
<CheckBox
android:id="#+id/cb_offer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_weight="1"
android:checked="false"
android:text="Selecionar apenas ofertas" />
</LinearLayout>
</LinearLayout>
</ScrollView>
</android.support.v7.widget.CardView>
</LinearLayout>
Everything works fine (spinner, cardview etc) but i always get NullPointerException because the TextView and i don't know why. Here goes my log:
FATAL EXCEPTION: main
Process: com.catafeira.catafeira, PID: 2419
Theme: themes:{default=overlay:system, iconPack:system, fontPkg:system, com.android.systemui=overlay:system, com.android.systemui.navbar=overlay:system}
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference
at com.catafeira.catafeira.SalesActivity.dialogFiltro(SalesActivity.java:281)
at com.catafeira.catafeira.SalesActivity.onOptionsItemSelected(SalesActivity.java:432)
at android.app.Activity.onMenuItemSelected(Activity.java:2914)
at android.support.v4.app.FragmentActivity.onMenuItemSelected(FragmentActivity.java:403)
at android.support.v7.app.AppCompatActivity.onMenuItemSelected(AppCompatActivity.java:189)
at android.support.v7.view.WindowCallbackWrapper.onMenuItemSelected(WindowCallbackWrapper.java:100)
at android.support.v7.view.WindowCallbackWrapper.onMenuItemSelected(WindowCallbackWrapper.java:100)
at android.support.v7.app.ToolbarActionBar$2.onMenuItemClick(ToolbarActionBar.java:69)
at android.support.v7.widget.Toolbar$1.onMenuItemClick(Toolbar.java:169)
at android.support.v7.widget.ActionMenuView$MenuBuilderCallback.onMenuItemSelected(ActionMenuView.java:760)
at android.support.v7.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:811)
at android.support.v7.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:152)
at android.support.v7.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:958)
at android.support.v7.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:948)
at android.support.v7.widget.ActionMenuView.invokeItem(ActionMenuView.java:618)
at android.support.v7.view.menu.ActionMenuItemView.onClick(ActionMenuItemView.java:139)
at android.view.View.performClick(View.java:5204)
at android.view.View$PerformClick.run(View.java:21158)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5461)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
EDIT: I know what is a NullPointerException, I already checked the previous posts on the subject, but no problem is the same as mine
I think the problem is with findViewByID. The documentation says
findViewById
Added in API level 1
View findViewById (int id)
Finds a child view with the given identifier. Returns null if the specified child view does not exist or the dialog has not yet been fully created (for example, via show() or create()).
It is just possible that since you are calling show() later the textView might not be created. I would do this
View dialogView = LayoutInflater.from(context).inflate(R.layout.dialog_filtro, null);
Button bt_cancelar = (Button) dialogView.findViewById(R.id.cb_filtro_cancelar);
Button bt_aceitar = (Button) dialogView.findViewById(R.id.cb_filtro_aceitar);
seek_preco = (SeekBar) dialogView.findViewById(R.id.sb_preco_max);
tv_filtro = (TextView) dialogView.findViewById(R.id.tv_filtro_preco);
spinner_categoria = (Spinner) dialogView.findViewById(R.id.spinner_categoria);
spinner_vendedor = (Spinner) dialogView.findViewById(R.id.spinner_vendedor);
dialog.setContentView(dialogView)
dialog.show();
spinner_categoria.setAdapter(ArrayAdapter.createFromResource(
this, R.array.categoria_array, android.R.layout.simple_spinner_item));
spinner_vendedor.setAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item,listVendedor));
tv_filtro.setText("oi");
Change the XML to the following
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:cardview="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="#+id/card"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:foreground="#drawable/border_card"
android:layout_margin="8dp"
card_view:cardElevation="2dp"
card_view:cardMaxElevation="8dp">
<ScrollView
android:id="#+id/scrollView2"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:orientation="vertical">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="#+id/cb_filtro_cancelar"
android:layout_width="70dp"
android:layout_height="30dp"
android:background="#color/colorPrimary"
android:elevation="2dp"
android:text="X"
android:textColor="#android:color/white" />
<Button
android:id="#+id/cb_filtro_aceitar"
android:layout_width="70dp"
android:layout_height="30dp"
android:layout_gravity="end"
android:background="#color/colorPrimary"
android:elevation="2dp"
android:text="Aceitar"
android:textColor="#android:color/white" />
</FrameLayout>
<TextView
android:id="#+id/textView9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="5dp"
android:text="Filtrar por"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#color/colorPrimary" />
<TextView
android:id="#+id/tv_label_categoria"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_weight="1"
android:gravity="center"
android:text="Categoria"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Spinner
android:id="#+id/spinner_categoria"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:spinnerMode="dialog" />
<TextView
android:id="#+id/tv_label_vendedor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_weight="1"
android:gravity="center"
android:text="Supermercado"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Spinner
android:id="#+id/spinner_vendedor"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:spinnerMode="dialog" />
<TextView
android:id="#+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Preço máximo"
android:textAppearance="?android:attr/textAppearanceMedium" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal">
<SeekBar
android:id="#+id/sb_preco_max"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:indeterminate="false"
android:max="100"
android:progress="5" />
<TextView
android:id="#+id/tv_filtro_preco"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:text="5"
android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout>
<View
android:id="#+id/rv_shoppingcart_separator"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginBottom="2dp"
android:layout_marginTop="10dp"
android:background="#android:color/darker_gray" />
<TextView
android:id="#+id/tv_label_oerdenar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="15dp"
android:text="Ordenar por"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#color/colorPrimary" />
<TextView
android:id="#+id/textView11"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Preço:"
android:textAppearance="?android:attr/textAppearanceMedium" />
<RadioGroup
android:id="#+id/group_preco"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:layout_marginLeft="5dp"
android:gravity="center"
android:orientation="horizontal">
<RadioButton
android:id="#+id/rb_preco_maior"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:checked="false"
android:text="Maior" />
<RadioButton
android:id="#+id/rb_preco_menor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:checked="false"
android:text="Menor" />
</RadioGroup>
<TextView
android:id="#+id/tv_label_data_Validade"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:layout_weight="1"
android:text="Data de validade:"
android:textAppearance="?android:attr/textAppearanceMedium" />
<RadioGroup
android:id="#+id/group_validade"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:layout_weight="1"
android:gravity="center"
android:orientation="horizontal">
<RadioButton
android:id="#+id/rb_validade_maior"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:checked="false"
android:text="Maior" />
<RadioButton
android:id="#+id/rb_validade_menor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:checked="false"
android:text="Menor" />
</RadioGroup>
<TextView
android:id="#+id/tv_label_ofertas"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginTop="10dp"
android:text="Apenas ofertas:"
android:textAppearance="?android:attr/textAppearanceMedium" />
<CheckBox
android:id="#+id/cb_offer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_weight="1"
android:checked="false"
android:text="Selecionar apenas ofertas" />
</LinearLayout>
</ScrollView>
</android.support.v7.widget.CardView>
Hope this helps!
SOLVED
The problem was something related android material design, I didn't note before that some layouts has 2 files, so some files were outdated -.-
Thanks for everyone that tried to help.

how to expand and collapse the textView which is having EditText as its child

i am new to android..In my xml file i have used three textviews,
inside that i have used three edittext for every textview..
what i want is when i press a particular textview it has to expand to get their
child(edittexts)..and when i again press the textview should collapse back.
Now in my code when i press textview it expands,but when i press again its not collapsing.
Below is my code..any help would be appreciated...thanks in advance..
Java file
CategoryPage.java
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
public class CategoryPage extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_category_page);
TextView btnProfile = (TextView) findViewById(R.id.btnprofile);
TextView btnSettings = (TextView) findViewById(R.id.btncitizen);
TextView btnPrivacy = (TextView) findViewById(R.id.btnprivacy);
View panelProfile = findViewById(R.id.panelProfile);
panelProfile.setVisibility(View.GONE);
View panelSettings = findViewById(R.id.panelSettings);
panelSettings.setVisibility(View.GONE);
View panelPrivacy = findViewById(R.id.panelPrivacy);
panelPrivacy.setVisibility(View.GONE);
btnProfile.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// DO STUFF
View panelProfile = findViewById(R.id.panelProfile);
panelProfile.setVisibility(View.VISIBLE);
View panelSettings = findViewById(R.id.panelSettings);
panelSettings.setVisibility(View.GONE);
View panelPrivacy = findViewById(R.id.panelPrivacy);
panelPrivacy.setVisibility(View.GONE);
}
});
btnSettings.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// DO STUFF
View panelProfile = findViewById(R.id.panelProfile);
panelProfile.setVisibility(View.GONE);
View panelSettings = findViewById(R.id.panelSettings);
panelSettings.setVisibility(View.VISIBLE);
View panelPrivacy = findViewById(R.id.panelPrivacy);
panelPrivacy.setVisibility(View.GONE);
}
});
btnPrivacy.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// DO STUFF
View panelProfile = findViewById(R.id.panelProfile);
panelProfile.setVisibility(View.GONE);
View panelSettings = findViewById(R.id.panelSettings);
panelSettings.setVisibility(View.GONE);
View panelPrivacy = findViewById(R.id.panelPrivacy);
panelPrivacy.setVisibility(View.VISIBLE);
}
});
}
}
XML File
activity_category_page.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"
android:background="#fff">
<LinearLayout android:id="#+id/header"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#fff"
android:paddingLeft="0dp"
android:paddingRight="0dp"
android:paddingTop="5dip"
android:paddingBottom="5dip">
<ImageView
android:id="#+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="0dp"
android:src="#drawable/miiskylogo" />
</LinearLayout>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#+id/header" >
<LinearLayout
android:id="#+id/root_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFFFF"
android:layout_weight="1"
android:layout_marginTop="10dp"
android:layout_marginLeft="7dp"
android:layout_marginRight="7dp"
android:orientation="vertical">
<TextView
android:id="#+id/textview1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
android:text="#string/Text"
android:textSize="20dp"
android:textStyle="bold"/>
<TextView
android:id="#+id/textview2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textview1"
android:text="#string/Text2"
android:layout_marginBottom="10dp"
android:textSize="13dp"
/>
<TextView
android:id="#+id/btnprofile"
android:layout_width="match_parent"
android:layout_height="35dp"
android:paddingLeft="10dp"
android:paddingTop="10dp"
android:background="#drawable/verifyedit"
android:text="Profile Vault"
android:textColor="#000"
android:textSize="15dp" />
<LinearLayout
android:id="#+id/panelProfile"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#FFFFFFFF">
<LinearLayout
android:id="#+id/panelProfile1"
android:layout_width="280dp"
android:layout_height="40dp"
android:layout_weight="1"
android:layout_marginTop="17dp"
android:layout_gravity="center_horizontal"
android:background="#FFFFFFFF"
android:orientation="horizontal" >
<EditText
android:id="#+id/salutation"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.81"
android:background="#drawable/verifyedit"
android:ems="10"
android:paddingLeft="10dp"
android:hint="Salutation" >
<requestFocus />
</EditText>
</LinearLayout>
<LinearLayout
android:id="#+id/panelProfile2"
android:layout_width="280dp"
android:layout_height="40dp"
android:layout_weight="1"
android:layout_marginTop="8dp"
android:layout_gravity="center_horizontal"
android:background="#FFFFFFFF"
android:orientation="horizontal" >
<EditText
android:id="#+id/firstname"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.81"
android:background="#drawable/verifyedit"
android:ems="10"
android:paddingLeft="10dp"
android:hint="First Name" />
</LinearLayout>
<LinearLayout
android:id="#+id/panelProfile3"
android:layout_width="280dp"
android:layout_height="40dp"
android:layout_weight="1"
android:layout_marginTop="8dp"
android:layout_gravity="center_horizontal"
android:background="#FFFFFFFF"
android:orientation="horizontal" >
<EditText
android:id="#+id/middlename"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.81"
android:background="#drawable/verifyedit"
android:ems="10"
android:paddingLeft="10dp"
android:hint="Middle Name" />
</LinearLayout>
<LinearLayout
android:id="#+id/panelProfile4"
android:layout_width="280dp"
android:layout_height="40dp"
android:layout_weight="1"
android:layout_marginTop="8dp"
android:layout_gravity="center_horizontal"
android:background="#FFFFFFFF"
android:orientation="horizontal" >
<EditText
android:id="#+id/lastname"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.81"
android:background="#drawable/verifyedit"
android:ems="10"
android:paddingLeft="10dp"
android:hint="Last Name" />
</LinearLayout>
</LinearLayout>
<TextView
android:id="#+id/btncitizen"
android:layout_width="match_parent"
android:layout_height="35dp"
android:paddingLeft="10dp"
android:paddingTop="10dp"
android:layout_marginTop="15dp"
android:background="#drawable/verifyedit"
android:text="Citizenship/Registration"
android:textColor="#000"
android:textSize="15dp" />
<LinearLayout
android:id="#+id/panelSettings"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#FFFFFFFF">
<LinearLayout
android:id="#+id/panelSettings1"
android:layout_width="280dp"
android:layout_height="40dp"
android:layout_weight="1"
android:layout_marginTop="17dp"
android:layout_gravity="center_horizontal"
android:background="#FFFFFFFF"
android:orientation="horizontal" >
<EditText
android:id="#+id/currentaddress"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.81"
android:background="#drawable/verifyedit"
android:ems="10"
android:paddingLeft="10dp"
android:hint="Current address" >
<requestFocus />
</EditText>
</LinearLayout>
<LinearLayout
android:id="#+id/panelSettings2"
android:layout_width="280dp"
android:layout_height="40dp"
android:layout_weight="1"
android:layout_marginTop="8dp"
android:layout_gravity="center_horizontal"
android:background="#FFFFFFFF"
android:orientation="horizontal" >
<EditText
android:id="#+id/houseno"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.81"
android:background="#drawable/verifyedit"
android:ems="10"
android:paddingLeft="10dp"
android:hint="House no" />
</LinearLayout>
<LinearLayout
android:id="#+id/panelSettings3"
android:layout_width="280dp"
android:layout_height="40dp"
android:layout_weight="1"
android:layout_marginTop="8dp"
android:layout_gravity="center_horizontal"
android:background="#FFFFFFFF"
android:orientation="horizontal" >
<EditText
android:id="#+id/roadno"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.81"
android:background="#drawable/verifyedit"
android:ems="10"
android:paddingLeft="10dp"
android:hint="Road no" />
</LinearLayout>
<LinearLayout
android:id="#+id/panelSettings4"
android:layout_width="280dp"
android:layout_height="40dp"
android:layout_weight="1"
android:layout_marginTop="8dp"
android:layout_gravity="center_horizontal"
android:background="#FFFFFFFF"
android:orientation="horizontal" >
<EditText
android:id="#+id/location"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.81"
android:background="#drawable/verifyedit"
android:ems="10"
android:paddingLeft="10dp"
android:hint="Location" />
</LinearLayout>
</LinearLayout>
<TextView
android:id="#+id/btnprivacy"
android:layout_width="match_parent"
android:layout_height="35dp"
android:paddingLeft="10dp"
android:paddingTop="10dp"
android:layout_marginTop="15dp"
android:background="#drawable/verifyedit"
android:text="Banking"
android:textColor="#000"
android:textSize="15dp" />
<LinearLayout
android:id="#+id/panelPrivacy"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#FFFFFFFF">
<LinearLayout
android:id="#+id/panelPrivacy1"
android:layout_width="280dp"
android:layout_height="40dp"
android:layout_weight="1"
android:layout_marginTop="17dp"
android:layout_gravity="center_horizontal"
android:background="#FFFFFFFF"
android:orientation="horizontal" >
<EditText
android:id="#+id/bankacc"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.81"
android:background="#drawable/verifyedit"
android:ems="10"
android:paddingLeft="10dp"
android:hint="Bank account no" >
<requestFocus />
</EditText>
</LinearLayout>
<LinearLayout
android:id="#+id/panelPrivacy2"
android:layout_width="280dp"
android:layout_height="40dp"
android:layout_weight="1"
android:layout_marginTop="8dp"
android:layout_gravity="center_horizontal"
android:background="#FFFFFFFF"
android:orientation="horizontal" >
<EditText
android:id="#+id/acctype"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.81"
android:background="#drawable/verifyedit"
android:ems="10"
android:paddingLeft="10dp"
android:hint="Account Type" />
</LinearLayout>
<LinearLayout
android:id="#+id/panelPrivacy3"
android:layout_width="280dp"
android:layout_height="40dp"
android:layout_weight="1"
android:layout_marginTop="8dp"
android:layout_gravity="center_horizontal"
android:background="#FFFFFFFF"
android:orientation="horizontal" >
<EditText
android:id="#+id/bankcredit"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.81"
android:background="#drawable/verifyedit"
android:ems="10"
android:paddingLeft="10dp"
android:hint="Bank Credit Card No" />
</LinearLayout>
</LinearLayout>
</ScrollView>
</RelativeLayout>
check if view is visible or not onClick of TextView:
if(panelProfile.getVisibility() == View.VISIBLE) {
panelProfile.setVisiblity(View.GONE);
} else {
panelProfile.setVisiblity(View.VISIBLE);
}
Note: You are declaring below code multiple times, instead just do it only once.
View panelProfile = findViewById(R.id.panelProfile);
same with,
View panelSettings = findViewById(R.id.panelSettings);
View panelPrivacy = findViewById(R.id.panelPrivacy);

Android: List View and Scroll View compatability

A quick note about my application. This is an app that uses an API to get server requests about specific players for a game called League of Legends (LoL)
I recently changed my code from a static layout of 10 pre-set most recent matches to a ListView in order to avoid cludder as well in case a player did not have 10 recent matches.
The issue I am having with this ListView, is that when it is created, you can not scroll up and down through it. That is to say that it is created in a very small height, and when you scroll in it, the page doesn't scroll, the ListView itself scrolls. This is not desirable. I would rather have the user scroll the whole screen than just the small portion of the ListView.
I constructed my xml file like so:
<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=".MainActivity">
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:orientation="vertical">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:orientation="horizontal"
android:paddingLeft="#dimen/activity_horizontal_margin">
<EditText
android:id="#+id/summoner_name"
android:layout_width="210dp"
android:layout_height="wrap_content"
android:hint="Summoner Name"
android:imeOptions="actionSend"
android:lines="1" />
<Spinner
android:id="#+id/regions"
android:layout_width="60dp"
android:layout_height="wrap_content" />
<Button
android:id="#+id/search_button"
android:layout_width="45dp"
android:layout_height="45dp"
android:background="#drawable/searchbuttononclick" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="9dp"
android:orientation="horizontal"
android:paddingLeft="#dimen/activity_horizontal_margin">
<ImageView
android:id="#+id/leagueicon"
android:layout_width="160dp"
android:layout_height="150dp" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="20dp" />
<TextView
android:id="#+id/summoner_name_after_search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:textSize="22dp"
android:textStyle="bold" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:orientation="horizontal">
<TextView
android:id="#+id/league_tier"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#ff0060a8"
android:textSize="18dp" />
<TextView
android:id="#+id/league_points"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:textSize="18dp" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:orientation="horizontal">
<TextView
android:id="#+id/ranked_wins"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#ff00b515"
android:textSize="18dp" />
<TextView
android:id="#+id/slash_between_wins_and_losses"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:textColor="#ff817a81"
android:textSize="18dp" />
<TextView
android:id="#+id/ranked_losses"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:textColor="#ffb5000f"
android:textSize="18dp" />
</LinearLayout>
<TextView
android:id="#+id/what_were_you_last_season"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:textColor="#ff817a81"
android:textSize="18dp" />
</LinearLayout>
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center_horizontal"
android:textSize="16dp"
android:id="#+id/normal_title"
android:textStyle="bold"
android:textColor="#ff000000" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="120dp"
android:orientation="horizontal"
android:baselineAligned="false">
<LinearLayout
android:layout_width="0dp"
android:layout_height="120dp"
android:layout_weight="1"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="120dp"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="120dp"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="38dp"
android:paddingLeft="5dp"
android:id="#+id/normal_wins"
android:gravity="center_vertical"
android:textSize="16dp"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="2dp"
android:id="#+id/normal_space_one"/>
<TextView
android:layout_width="match_parent"
android:gravity="center_vertical"
android:paddingLeft="5dp"
android:textSize="16dp"
android:id="#+id/normal_kills"
android:layout_height="38dp"
/>
<TextView
android:layout_width="match_parent"
android:id="#+id/normal_space_two"
android:layout_height="2dp"/>
<TextView
android:layout_width="match_parent"
android:gravity="center_vertical"
android:paddingLeft="5dp"
android:id="#+id/normal_assists"
android:textSize="16dp"
android:layout_height="38dp"
/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="120dp"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="38dp"
android:gravity="center_vertical"
android:id="#+id/normal_wins_value"
android:paddingLeft="5dp"
android:textSize="16dp"
/>
<TextView
android:layout_width="match_parent"
android:id="#+id/normal_space_three"
android:layout_height="2dp"/>
<TextView
android:layout_width="match_parent"
android:gravity="center_vertical"
android:id="#+id/normal_kills_value"
android:textSize="16dp"
android:paddingLeft="5dp"
android:layout_height="38dp"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="2dp"
android:id="#+id/normal_space_four"/>
<TextView
android:layout_width="match_parent"
android:id="#+id/normal_assists_value"
android:gravity="center_vertical"
android:paddingLeft="5dp"
android:textSize="16dp"
android:layout_height="38dp"
/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="120dp"
android:orientation="vertical"
android:layout_weight="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="120dp"
android:orientation="horizontal"
android:baselineAligned="false">
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="120dp"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="38dp"
android:paddingLeft="5dp"
android:id="#+id/normal_minion_kills"
android:gravity="center_vertical"
android:textSize="16dp"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="2dp"
android:id="#+id/normal_space_five"/>
<TextView
android:layout_width="match_parent"
android:gravity="center_vertical"
android:paddingLeft="5dp"
android:textSize="14dp"
android:id="#+id/normal_neutral_minion_kills"
android:layout_height="38dp"
android:layout_gravity="center_horizontal"/>
<TextView
android:layout_width="match_parent"
android:id="#+id/normal_space_six"
android:layout_height="2dp"/>
<TextView
android:layout_width="match_parent"
android:gravity="center_vertical"
android:paddingLeft="5dp"
android:id="#+id/normal_turrets_destroyed"
android:textSize="12dp"
android:layout_height="38dp"
/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="120dp"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="38dp"
android:paddingLeft="5dp"
android:gravity="center_vertical"
android:id="#+id/normal_minion_kills_value"
android:textSize="16dp"
/>
<TextView
android:layout_width="match_parent"
android:id="#+id/normal_space_seven"
android:layout_height="2dp"/>
<TextView
android:layout_width="match_parent"
android:gravity="center_vertical"
android:paddingLeft="5dp"
android:id="#+id/neutral_minion_kills_value"
android:textSize="16dp"
android:layout_height="38dp"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="2dp"
android:id="#+id/normal_space_eight"/>
<TextView
android:layout_width="match_parent"
android:id="#+id/normal_turrets_destroyed_value"
android:gravity="center_vertical"
android:paddingLeft="5dp"
android:textSize="16dp"
android:layout_height="38dp"
/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
<com.ryanfolz.riotgamesapi.SwagObListView
android:id="#+id/list"
android:layout_width="wrap_content"
android:layout_height="fill_parent" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="20dp"></LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
As you see, I created a custom ListView called "SwagObListView"
Here is the code for that:
public class SwagObListView extends ListView implements AdapterView.OnItemClickListener {
private List<SwagOb> swagList;
private SwagObClickListener swagClicked;
public SwagObListView(Context context) {
super(context);
}
public SwagObListView(Context context, AttributeSet attrs) {
super(context, attrs);
this.swagList = swagList;
this.swagClicked = swagClicked;
}
#Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
if (swagClicked != null) {
swagClicked.onConnectionClicked(swagList.get(i));
}
}
public void setOnSwagObClickListener(SwagObClickListener c){
this.swagClicked = c;
}
public void setSwag(List<SwagOb> swagList) {
this.swagList = swagList;
SwagObAdapter swagDapter = new SwagObAdapter(getContext(), swagList);
setAdapter(swagDapter);
setOnItemClickListener(this);
}
}
As for the SwagOb class, here is the code for that:
public class SwagOb {
private String gameType;
private Drawable championPicturePlayed;
private String kills;
private String deaths;
private Drawable[] summonerSpells;
private String assists;
private String cs;
private String gold;
private boolean won;
private Drawable itemOne, itemTwo, itemThree, itemFour, itemFive, itemSix;
private Drawable[] tempDrawable;
private Drawable[] tempDrawable2;
private String[] tempString;
private SearchPlayerFragment activty;
private CollectUserData data;
public SwagOb(String gameType, Drawable championPicturePlayed, String kills, String deaths, Drawable[] summonerSpells,
String assists, String cs, String gold, boolean won, Drawable itemOne, Drawable itemTwo, Drawable itemThree, Drawable itemFour,
Drawable itemFive, Drawable itemSix, Drawable[] tempDrawable, Drawable[] tempDrawable2, String[] tempString, SearchPlayerFragment activity, CollectUserData data){
this.gameType = gameType;
this.championPicturePlayed = championPicturePlayed;
this.kills = kills;
this.deaths = deaths;
this.summonerSpells = summonerSpells;
this.itemFive = itemFive;
this.itemTwo = itemTwo;
this.itemOne = itemOne;
this.itemThree = itemThree;
this.itemFour = itemFour;
this.itemSix = itemSix;
this.assists = assists;
this.cs = cs;
this.gold = gold;
this.won = won;
this.tempDrawable = tempDrawable;
this.tempDrawable2 = tempDrawable2;
this.tempString = tempString;
this.activty = activity;
this.data = data;
}
(This also has getters and setters but that isn't important.)
Anyone know any ideas as to why this is acting this way?
Android does not allow to add ListView inside ScrollView. Possible workaround for this will be remove scrollview and adding top content to listivew header and bottom content into listview footer.
In your scroll view add this property That will do the trick
android:fillViewport="true"

add blink to customized listview Item?

i have created a listview contains multiple items, and i added a border to those items so it would look like this:
because of this customized border the original blink of an item get blocked so it doesn't appear, and i've tried to add a blink through animation but there is too much delay and too much work on the main thread, i also used animation inside threads but it is the same with the delay thing, which force me to forget about animation so is there anyway that i can make the item blink when its clicked without using animation or with using it but in an efficient way and by the way i used blink animation inside my onItemClickListener you can find it in the code below:
onItemClickListener that handle the blink:
dataList.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> arg0, final View arg1,
final int arg2, long arg3) {
// TODO Auto-generated method stub
tvWarningNoEmp.setVisibility(View.GONE);
// adding blink
final Animation animation = new AlphaAnimation(
1, 0); // Change
// alpha
// from
// fully
// visible
// to
// invisible
animation.setDuration(100); // duration - half a
// second
animation
.setInterpolator(new LinearInterpolator()); // do
// not
// alter
// animation
// rate
animation.setRepeatCount(Animation.INFINITE); // Repeat
// animation
// infinitely
animation.setRepeatMode(Animation.REVERSE);
arg1.startAnimation(animation);
// blink one time timer
new CountDownTimer(100, 100) {// CountDownTimer(edittext1.getText()+edittext2.getText())
// also parse it to long
public void onTick(long millisUntilFinished) {
// here you can have your logic to set text to
// edittext
}
public void onFinish() {
arg1.clearAnimation();
}
}.start();
// set margins for tickets buttons
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
params.setMargins(0, 0, 30, 0);
bAssign.setLayoutParams(params);
LinearLayout.LayoutParams paramsO = new LinearLayout.LayoutParams(
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
paramsO.setMargins(110, 0, 0, 0);
bEmpChat.setLayoutParams(paramsO);
noEmpLayout.setVisibility(LinearLayout.GONE);
empLayout.setVisibility(LinearLayout.VISIBLE);
Employee item = adapter.getItem(arg2);
ivEmpIcon.setBackgroundResource(R.drawable.free);
tvEmpName.setText(" " + item.getEmpName());
tvEmpDetails.setText(" " + item.getEmpDetails());
empLongitude = item.getEmpLongitude();
empLatitude = item.getEmpLatitude();
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(new LatLng(empLatitude, empLongitude))
.zoom(15).build();
googleEmpMap.animateCamera(CameraUpdateFactory
.newCameraPosition(cameraPosition));
MarkerOptions marker = new MarkerOptions().position(
new LatLng(empLatitude, empLongitude)).title(
tvEmpName.getText().toString());
marker.icon(BitmapDescriptorFactory
.defaultMarker(BitmapDescriptorFactory.HUE_RED));
googleEmpMap.addMarker(marker);
// based on item add info to intent
// hide button directions
bEmpDirections.setVisibility(View.GONE);
// current address
Geocoder geocoder;
List<Address> addresses;
geocoder = new Geocoder(getApplicationContext(), Locale
.getDefault());
try {
addresses = geocoder.getFromLocation(empLatitude,
empLongitude, 1);
String street = addresses.get(0).getAddressLine(0);
String state = addresses.get(0).getAdminArea();
String country = addresses.get(0).getCountryName();
tvEmpCurrentAdd.setText(" " + country + "-" + state
+ "-" + street + " st.");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();}
}
});
ListView Layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/redborder" >
<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"
>
<Button
android:id="#+id/btnBack"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:background="#drawable/back" />
<TextView
android:id="#+id/tvWarningNoEmp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="choose an employee from here to assign this problem to!"
android:textColor="#FF0000"
android:layout_marginLeft="400dp"
android:visibility="gone"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="40dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:layout_weight="2"
android:background="#drawable/pepsiborder"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:background="#drawable/blueborder"
android:orientation="horizontal"
android:padding="10dp" >
<ImageView
android:id="#+id/TicketIcon"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_gravity="center_vertical"
android:layout_weight="0.1" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="0.7"
android:gravity="center_vertical"
android:orientation="vertical" >
<TextView
android:id="#+id/ticketCat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="7dp"
android:gravity="center_vertical"
android:textColor="#D3D9FF"
android:textSize="17sp" />
</LinearLayout>
</LinearLayout>
<fragment
android:id="#+id/ticketMap"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp" />
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:orientation="vertical" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="State:"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#D3D9FF" />
<TextView
android:id="#+id/ticketState"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textColor="#D3D9FF" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Ticket No:"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#D3D9FF" />
<TextView
android:id="#+id/ticketNo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textColor="#D3D9FF" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/textView12"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Report Date:"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#D3D9FF" />
<TextView
android:id="#+id/ticketReportDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textColor="#D3D9FF" />
</LinearLayout>
<TextView
android:id="#+id/textView13"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Details:"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#D3D9FF" />
<TextView
android:id="#+id/ticketDetails"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textColor="#D3D9FF" />
</LinearLayout>
</ScrollView>
<LinearLayout
android:id="#+id/llBtn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_marginBottom="10dp"
android:layout_marginTop="170dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="#drawable/blueborder"
android:orientation="horizontal"
android:padding="10dp" >
<Button
android:id="#+id/btnTicketDirections"
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_weight="1"
android:background="#drawable/directions" />
<Button
android:id="#+id/btnSolve"
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_weight="1"
android:background="#drawable/solve" />
<Button
android:id="#+id/btnOther"
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_weight="1"
android:background="#drawable/other" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/llListView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="40dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:layout_weight="2"
android:background="#drawable/pepsiborder"
android:orientation="vertical" >
<TextView
android:id="#+id/textView124"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#D3D9FF"
android:text="Free Employees"
android:textSize="30sp"
android:gravity="left"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:textAppearance="?android:attr/textAppearanceLarge" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_marginLeft="20dp"
>
<ListView
android:id="#+id/listTic"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginRight="5dp"
android:layout_marginTop="20dp"
android:divider="#android:color/transparent"
android:dividerHeight="10dp" >
</ListView>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:layout_weight="2"
android:id="#+id/noempLayout"
android:background="#android:color/transparent"
android:orientation="vertical" >
<TextView
android:text="Please select free Employee to handle this problem!"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:layout_marginTop="300dp"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="40dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:layout_weight="2"
android:id="#+id/empLayout"
android:background="#drawable/pepsiborder"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:background="#drawable/blueborder"
android:orientation="horizontal"
android:padding="10dp" >
<ImageView
android:id="#+id/empIcon"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_gravity="center_vertical"
android:layout_weight="0.1" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="0.7"
android:gravity="center_vertical"
android:orientation="vertical" >
<TextView
android:id="#+id/empName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="7dp"
android:gravity="center_vertical"
android:textColor="#D3D9FF"
android:textSize="17sp" />
</LinearLayout>
</LinearLayout>
<fragment
android:id="#+id/empMap"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:orientation="vertical" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/textView33"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Current Address:"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#D3D9FF" />
<TextView
android:id="#+id/empAddress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textColor="#D3D9FF" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/textView22"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Details:"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#D3D9FF" />
<TextView
android:id="#+id/empDetails"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textColor="#D3D9FF" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/llBtn2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_marginTop="220dp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="#drawable/blueborder"
android:orientation="horizontal"
android:padding="10dp" >
<Button
android:id="#+id/btnEmpDirections"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_weight="1"
android:layout_gravity="center"
android:background="#drawable/directions" />
<Button
android:id="#+id/btnEmpChat"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_weight="1"
android:layout_gravity="center"
android:background="#drawable/chat" />
<Button
android:id="#+id/btnEmpAssign"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_weight="1"
android:layout_gravity="center"
android:background="#drawable/assign" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
ListView Item Layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="280dp"
android:layout_height="90dp"
android:orientation="horizontal"
android:background="#drawable/border"
android:layout_marginTop="10dp"
android:padding="10dp"
>
<ImageView
android:id="#+id/imgIcon"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_weight="0.1"
android:gravity="center_vertical"
/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:layout_weight="0.7"
android:gravity="center_vertical"
>
<TextView
android:id="#+id/txtTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:textSize="17sp"
android:textColor="#D3D9FF"
android:layout_gravity="center_vertical"
android:layout_marginLeft="7dp"
/>
<TextView
android:id="#+id/txtTitle1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:layout_gravity="center_vertical"
android:textSize="13sp"
android:textColor="#D3D9FF"
android:layout_marginLeft="7dp"
/>
</LinearLayout>
</LinearLayout>
Border.xml:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"
>
<stroke
android:width="2dip"
android:color="#8D8D8D" />
<corners android:radius="10dip"/>
<solid android:color="#464A4F" />
</shape>
any help is truly appreciated.
If you want a view to blink:
public void blink(final View v) {
v.setBackgroundColor(Color.DKGRAY);
v.animate().setDuration(25).alpha(0).withEndAction(new Runnable() {
#Override
public void run() {
v.setBackgroundResource(R.drawable.standard_key_normal);
v.setAlpha(1);
}
});
}
Send your View to this function, replace the background with whatever drawable or color resource you want. If you want multiple blinks put it in a for loop.
well i figure out how to reduce the delay and add blink effect without using animation and some how it worked for me and there is no more delay, what i did is I've changed the list's linear layouts to relative and that reduced the amount of nested layouts significantly then i added this method:
private void blink(final View v){
final Handler handler = new Handler();
new Thread(new Runnable() {
#Override
public void run() {
int timeToBlink = 1000; //in milissegunds
try{Thread.sleep(timeToBlink);}catch (Exception e) {}
handler.post(new Runnable() {
#Override
public void run() {
if(v == View.VISIBLE){
v.setVisibility(View.INVISIBLE);
}else{
v.setVisibility(View.VISIBLE);
}
blink();
}
});
}
}).start();
then i used it inside onItemClickListener() --> blink(arg1);
worked perfectly for me, also getting the current address was taking too much so i used Async so now there is no delay at all:
Async used as an inner class:
private class LongOperation extends AsyncTask<String, Void, String> {
String all;
#Override
protected String doInBackground(String... params) {
// current address
Geocoder geocoder;
List<Address> addresses;
geocoder = new Geocoder(getApplicationContext(), Locale
.getDefault());
try {
addresses = geocoder.getFromLocation(empLatitude,
empLongitude, 1);
String street = addresses.get(0).getAddressLine(0);
String state = addresses.get(0).getAdminArea();
String country = addresses.get(0).getCountryName();
all="" + country + "-" + state
+ "-" + street + " st.";
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();}
return all;
}
#Override
protected void onPostExecute(String result) {
tvEmpCurrentAdd.setText(all);
}
#Override
protected void onPreExecute() {}
#Override
protected void onProgressUpdate(Void... values) {}
}
and then i called it inside onItemClickListener:
new LongOperation().execute();
hope this will help others that had simillar problem.

Categories

Resources