小编use*_*154的帖子

如何使用Android中的LayoutInflater从动态创建的EditText中获取数据?

这是相对布局视图,它是动态创建的,如下所示:

布局

...所以我的问题是如何从这些动态元素中获取值并执行一些计算以在textview上显示结果,textview也是动态创建的.先谢谢你们!!

    public void goButtonClicked(View view) {
    maalContainer.removeAllViews();
    int numberofPlayersTolayout = (Integer) Integer.parseInt((String) numberOfPlayers.getSelectedItem());

    LayoutInflater inflater = (LayoutInflater) getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    LayoutParams params = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);

    for (int i = 0; i < numberofPlayersTolayout; i++) {
        View dynamicEntryView = inflater.inflate(R.layout.player_entry_item, null);
        maalContainer.addView(dynamicEntryView, params);
    }

}
Run Code Online (Sandbox Code Playgroud)

}

android relativelayout android-edittext layout-inflater

3
推荐指数
1
解决办法
6505
查看次数