user1099630
user1099630

Reputation: 23

Android :I can't get value in dialog while binding dynamic textviews through base adapter class

I got exception in dialog while binding dynamic textviews through base adapter class

i can get the dialog box but it doesnot bind the textview value hell.. plz help me.. wat i did wrong :)

Train_Origin_Destination.java

public void loadAutocomplete1(String strCmdTrain) {

c.moveToFirst(); if (c.isAfterLast() == false) {

        do {            

            listFrom1 = new ArrayList<String>(Arrays.asList(strComments));
            listTo1 = new ArrayList<String>(Arrays.asList(strComments));

            listFrom1.removeAll(Collections.singleton(null));

            HashMap<String, String> map = new HashMap<String, String>();
            map.put(KEY_Start, "Hello");

            listData.add(map);
            Log.e("map", map.toString());
            Log.e("list4", listData.toString());

            customAdapter = new MyCustomAdapter2(
                    Train_Origin_Destination.this, listData);
            lvTrainTime1.setAdapter(customAdapter);


        } while (c.moveToNext());

    }

onButtonClick Event

public void onClick(View arg0) {

    Log.d("Dialog", "Dialog");
    dialog = new Dialog(context1);
    //dialog.setContentView(R.layout.traintimings_dialog);
    //dialog.getWindow().getAttributes().windowAnimations = R.style.Animations_SmileWindow;
    dialog.setTitle("Train Timings");
    //dialog.setContentView(R.id.lvTrainTimings1);

if (chkSunday.isChecked()) {
        if (Area_Index < Area_Index1) {
            Log.d("Sunday", "Sunday");
        } else if (Area_Index > Area_Index1) {
            Log.d("SundayReverse", "SundayReverse");
        }
    } else {
        if (Area_Index < Area_Index1) {
            Log.d("Normal", "Normal");

            if (strSpSelectedItem.contentEquals("Beach - Tambaram")) {
                int id = Area_Index + 1;
                int id1 = Area_Index1 + 1;
                /*
                 * strCmdTrainFrom =
                 * "Beach_Thirumalpur_WeekD ays where _id='" + id +
                 * "' or _id='" + id1 + "'";
                 */
                strCmdTrainFrom = "Beach_Thirumalpur_WeekDays where _id='"
                        + id + "'";
                loadAutocomplete1(strCmdTrainFrom);

            }
        } else if (Area_Index > Area_Index1) {
            Log.d("NormalReverse", "NormalReverse");
        }
    }

    Log.d("DialogEndB4", listData.toString());
    dialog.show(); 
    Log.d("DialogEnd", "DialogEnd");


}

MyCustomAdapter2.java

public class MyCustomAdapter2 extends BaseAdapter {

private String[] strKeys;
private ArrayList<HashMap<String, String>> alData;
private Context context;
TextView txtBusNo, txtBusVia, txtBusServiceType, txtBusJourneyTime;
TextView[] tvStart;
ListView lvTrainTime1;
View rowView2;

public MyCustomAdapter2(Context context,
        ArrayList<HashMap<String, String>> listData) {

    super();
    Log.d("Custom", "Custom");
    this.alData = listData;
    this.context = context;
    Log.d("alData", alData.toString());
    Log.d("Custom1", "Custom1");

}

public int getCount() {
    // TODO Auto-generated method stub
    Log.d("alData.size()", String.valueOf(alData.size()));
    return alData.size();
}

public Object getItem(int position) {
    // TODO Auto-generated method stub
    return position;
}

public long getItemId(int position) {
    // TODO Auto-generated method stub
    return position;
}

public View getView(int position, View convertView, ViewGroup parent) {
    // TODO Auto-generated method stub
    Log.d("View", "View");
    rowView2 = convertView;
    if (rowView2 == null) {

        Log.d("View1", "View1");
        Train_Origin_Destination trDetails = new Train_Origin_Destination();
        // Inflate the layout, list_view.xml, in each row.
        LayoutInflater inflater = (LayoutInflater) context
                .getSystemService(context.LAYOUT_INFLATER_SERVICE);
        Log.d("View2", "View2");
        rowView2 = inflater
                .inflate(R.layout.textview_autofrom, null, false);

}

        txtBusNo = (TextView) rowView2.findViewById(R.id.idTvAutoFrom1);


        Log.d("View3", "View3");
        HashMap<String, String> hashmap = new HashMap<String, String>();


        txtBusNo.setText("Bus No : Hello");

        Log.d("View30", "View30");


        Log.d("View5", String.valueOf(rowView2));
    } else {

    }
    return rowView2;
}

Upvotes: 1

Views: 294

Answers (1)

stan0
stan0

Reputation: 11807

Well what you do is add lvTrainTime to the scr ScrollView than use it as a content view for the dialog. Maybe what you want to do is setContentView(scr);? If you do it this way scr will play the role of a container of the view. So basically you need to set the container as a content view.

EDIT - clarifications:

What I meant was that in your loadAutocomplete1 method you create a ScrollView scr = new ScrollView(this);. Later in the same method, after the loop, you add a view to that scroll view - scr.addView(lvTrainTime); and then set the content view of the dialog to be the mentioned view - dialog.setContentView(lvTrainTime);. You cant do that because scr and dialog are different controls and one view (lvTrainTime) can't have two parents. So, instead of setting the content view to be that view - lvTrainTime - I meant that you should set it's parent(container) as a content view. By the time I answered I thought it was scr that should be set as content view but I just saw that you actually put the scr in a tableLayout - tablelayout.addView(scr, new TableLayout.LayoutParams(LayoutParams.MATCH_PARENT, 50));. So your current situation is that lvTrainTime is inside scr and scr is inside tableLayout. So try dialog.setContentView(tableLayout); instead. In addition I am not sure what happens when you set the content view of the dialog twice so maybe you should try without dialog.setContentView(R.layout.traintimings_dialog); too.

Upvotes: 0

Related Questions