从listview适配器单击更新主布局

时间:2016-01-20 07:56:04

标签: android android-layout listview

在我的main.xml中,我有一个包含Textview用户名的linearLayout-userinfo。布局有(VISIBILITY:GONE),然后是userinfo布局下面的ListView

当我点击ImageView中的ListView并将用户名传递给textview时,我想让linearLayout-userinfo可见。

我的适配器代码中有以下内容,但不起作用:

img.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            String owner_username =  ((Map<String, String>)getItem(position)).get("owner_username");
            TextView username     = (TextView) findViewById(R.id.userinfo);
            username.setText(owner_username);
            LinearLayout userinfo = (LinearLayout) parent.findViewById(R.id.userinfo);
            userinfo.setVisibility(View.VISIBLE);
            Toast.makeText(view.getContext(), "ImageView clicked for the row = " + position, Toast.LENGTH_SHORT).show();
        }
    });

1 个答案:

答案 0 :(得分:0)

移动:

final TextView username     = (TextView) findViewById(R.id.userinfo);

final LinearLayout userinfo = (LinearLayout) parent.findViewById(R.id.userinfo);

img.setOnClickListener[...]