Quantcast
Channel: Active questions tagged listview - Stack Overflow
Viewing all articles
Browse latest Browse all 611

listview not showing in dialog (JAVA, Android)

$
0
0

I'm trying to show a dialog to the user with a list in it. It won't show up on the dialog no matter what I try.CODE:this is in TaskInputActivity where I create the dialog and the adapter for the listview (where I think the problem is):

    public void createDialog() {        Dialog d = new Dialog(this);        Log.d("Checkpoint A", "aaa");        View view = getLayoutInflater().inflate(R.layout.dialog_time_picker, null);        ListView day = view.findViewById(R.id.lvDay);        ArrayList<Integer> allDays = new ArrayList<>();        for (int i = 1; i <= 31; i++) {            allDays.add(i);        }        DayAdapter dayAdapter = new DayAdapter(allDays, d.getContext());        day.setAdapter(dayAdapter);        Log.d("Checkpoint B", "bbb");        TextView tvCurrentDate = findViewById(R.id.tvCurrentDate);        day.setOnItemClickListener(new AdapterView.OnItemClickListener() {            @Override            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {                String[] split = tvCurrentDate.getText().toString().split(String.valueOf('.'));                String date = (position + 1) +"." + split[1] +"." + split[2];                tvCurrentDate.setText(date);            }        });        Log.d("Checkpoint C", "ccc");        d.setContentView(R.layout.dialog_time_picker);        d.show();    }

this is the Adapter:

package com.example.todolistproj.Adapters;import android.app.Activity;import android.content.Context;import android.util.Log;import android.view.View;import android.view.ViewGroup;import android.widget.BaseAdapter;import android.widget.TextView;import com.example.todolistproj.Constants;import com.example.todolistproj.R;import org.w3c.dom.Text;import java.util.ArrayList;public class DayAdapter extends BaseAdapter {    private ArrayList<Integer> days;    private Context context;    public DayAdapter(Context c) {        days = new ArrayList<>();        for (int i = 1; i <= 31; i++) {            days.add(i);        }        Log.d("DAYS", days.toString());        context = c;    }    public DayAdapter(ArrayList<Integer> days, Context context) {        Log.d("CONSTRUCTOR", "2 params");        this.days = days;        this.context = context;    }    @Override    public int getCount() {        return days.size();    }    @Override    public Object getItem(int position) {        return days.get(position);    }    @Override    public long getItemId(int position) {        return position;    }    @Override    public View getView(int position, View convertView, ViewGroup parent) {        Log.d("GETVIEW", "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");        View view = convertView;        if (view == null)            view = ((Activity) context).getLayoutInflater().inflate(R.layout.custom_date_list_view, parent, false);        TextView tvItem = view.findViewById(R.id.tvItem);        int item = days.get(position);        tvItem.setText(item+"");        return view;    }}

XMLs:

the dialog xml (dialog_time_picker.xml) (don't worry about the LinearLayout in a LinearLayout I had a plan but I'm trying to solve this problem first):

<?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:orientation="vertical"><TextView        android:id="@+id/tvCurrentDate"        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:layout_gravity="center"        android:gravity="center"        android:layout_margin="20dp"        android:textSize="20dp"        android:text="1.1.1970" /><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:orientation="vertical"><ListView                android:id="@+id/lvDay"                android:layout_width="match_parent"                android:layout_height="wrap_context" /></LinearLayout></LinearLayout></LinearLayout>

custom_date_list_view.xml, pretty self explanatory:

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:orientation="vertical"><TextView        android:id="@+id/tvItem"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="TextView" /></LinearLayout>

PS: I'm aware that I can use a date picker dialog but I wanted to try this one out.

I searched everything related to this issue online but nothing helped. I don't really understand how the whole process of creating the ListView works so I can't thing of a way to even start understanding how this can be fixed.


Viewing all articles
Browse latest Browse all 611

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>