1

通过基本适配器类绑定动态文本视图时,我在对话框中遇到异常

我可以得到对话框,但它没有绑定textview值地狱..请帮助我..我做错了:)

Train_Origin_Destination.java

公共无效loadAutocomplete1(字符串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 事件

公共无效 onClick(查看 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;
}
4

1 回答 1

0

好吧,您所做的是将其添加lvTrainTimescrScrollView 中,而不是将其用作对话框的内容视图。也许你想做的是setContentView(scr);?如果这样做,scr将扮演视图容器的角色。所以基本上你需要将容器设置为内容视图。

编辑 - 澄清:

我的意思是在你的loadAutocomplete1方法中你创建一个ScrollView scr = new ScrollView(this);. 稍后在相同的方法中,在循环之后,向该滚动视图添加一个视图 -scr.addView(lvTrainTime);然后将对话框的内容视图设置为提到的视图 - dialog.setContentView(lvTrainTime);。您不能这样做,因为scrdialog是不同的控件,并且一个视图 ( lvTrainTime) 不能有两个父级。因此,与其将内容视图设置为该视图lvTrainTime- 我的意思是您应该将其父(容器)设置为内容视图。当我回答时,我认为scr应该将其设置为内容视图,但我刚刚看到您实际上将 - 放在scrtableLayout-中tablelayout.addView(scr, new TableLayout.LayoutParams(LayoutParams.MATCH_PARENT, 50));。所以你现在的情况就是lvTrainTime在里面scrscr在里面tableLayout。所以试试 dialog.setContentView(tableLayout);反而。此外,我不确定当您设置对话框的内容视图两次时会发生什么,所以也许您也应该尝试不dialog.setContentView(R.layout.traintimings_dialog);这样做。

于 2013-03-26T08:07:42.893 回答