I have a listview
.On click of particular item of listview
,i am opening a layout from bottom which has 3 buttons and on click of any of the 3 buttons i want to place a call,but when i click on any of the button i am getting null object reference even after creating objects of those button
public class CallActivity extends ListActivity {
private Button sales,service,insurance;
private static final String[] items={"Dahisar Brach","Borivali West ASC","Nagpada ASC"
,"Borivali East ASC","Kandivali West Workshop","Kandivali West"};
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.activity_call);
sales=findViewById(R.id.sales);
service=findViewById(R.id.service);
insurance=findViewById(R.id.insurance);
setListAdapter(new ArrayAdapter<String>(this,
R.layout.list_items,
items));
}
@Override
public void onListItemClick(ListView parent, View v, int position,
long id) {
final Dialog mBottomSheetDialog = new Dialog(CallActivity.this, R.style.MaterialDialogSheet);
mBottomSheetDialog.setContentView(R.layout.view); // your custom view.
mBottomSheetDialog.setCancelable(true);
mBottomSheetDialog.getWindow().setLayout(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
mBottomSheetDialog.getWindow().setGravity(Gravity.BOTTOM);
mBottomSheetDialog.show();
if(position==0){
sales.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Uri call = Uri.parse("tel:" + "02228921114");
Intent callNumber = new Intent(Intent.ACTION_DIAL, call);
callNumber = Intent.createChooser(callNumber, "Call Number");
startActivity(callNumber);
}
});
service.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Uri call = Uri.parse("tel:" + "101");
Intent callNumber = new Intent(Intent.ACTION_DIAL, call);
callNumber = Intent.createChooser(callNumber, "Call Number");
startActivity(callNumber);
}
});
insurance.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Uri call = Uri.parse("tel:" + "100");
Intent callNumber = new Intent(Intent.ACTION_DIAL, call);
callNumber = Intent.createChooser(callNumber, "Call Number");
startActivity(callNumber);
}
});
}
}
}
view(layout file)
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="To whom you want to call?"
android:gravity="center"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:text="Sales"
android:gravity="center"
android:id="@+id/sales"
/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:text="Service"
android:gravity="center"
android:id="@+id/service"
/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:text="Insurance"
android:id="@+id/insurance"
android:gravity="center"
/>
</LinearLayout>
What am i doing wrong,Please help.I even tried creating the object in onListItemClick
method,but i am getting the same error.
FYI,
I am using compile 'com.android.support:appcompat-v7:26.+', so i don't need to typecast my button