第一个问题和 android 的新手 - 希望这意味着有一个简单的解决方案,我刚刚完全错过了 - 这是希望......在这里。
我正在使用自定义 BaseExpandableListAdapter 来驱动 ExpandableListView 并在适配器内,我重写了 GetChildView 方法以显示具有 5 个按钮的自定义子项。
public class ExpandableListAdapter extends BaseExpandableListAdapter {
private Context context;
private ArrayList<String> groups;
private ArrayList<ArrayList<String>> children;
private int setCount;
private int currentSetNumber;
...
public View getChildView(int groupPosition, int childPosition, boolean isLastChild,
View convertView, ViewGroup parent) {
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.child_layout, null);
parent.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);
}
Button bPlus = (Button) convertView.findViewById(R.id.btnAddSet);
if(childPosition == 0){
Button bSetPlace = (Button) convertView.findViewById(R.id.bSetPlace1);
bSetPlace.setText("Set 1");
bSetPlace.setOnClickListener(new View.OnClickListener(){
***public void onClick(View v) {
// TODO Auto-generated method stub
Intent myIntent = new Intent(context,WeightEntryDialog.class);
context.startActivity(myIntent);
}***
});
... remainder of method (not relevant)
到目前为止没有任何问题,但是我似乎被困在放置在子按钮上的 onClick 方法中。我想做的是从我正在启动的意图(对话框)中获得结果。理想情况下,我会调用 startActivityForResult 但上下文中没有这样的方法可用。我也受到匿名类范围的限制。对话框正在显示,但我无法从中获取任何值,此外,由于缺乏反馈,我无法确定对话框何时关闭。
我想从对话框中返回两个整数。不确定是否有任何对话框代码相关,但这是标题。
public class WeightEntryDialog extends Activity {
我在 BaseExpandableListAdapter 类中走得太远了吗?我是否正在尝试在适配器中做一些我真的应该在其他地方做的事情,对我来说保持对可扩展列表中子项的控制很重要。希望我很清楚,有人可以提供一些指导。谢谢一堆。