有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java我想要两个列表视图同时滚动

我有一个活动,其中有两个列表视图

一个是带有imageview和textview的自定义listview,另一个是我找到滚动解决方案后的一个按钮

基本上左边是食物清单和图片,右边是购买清单
现在我无法同时滚动它们

public class list_activity extends AppCompatActivity {

  String[] itemname ={
        "Safari",
        "Camera",
        "Global",
        "FireFox",
        "UC Browser",
        "Android Folder",
        "VLC Player",
        "Cold War",
        "Whatsapp",
        "Google",
        "Java"
  };
  String[] buy={"one","two","two","two","two","two","two","two","two","two","two","two","two","two","two","two","two"};
  Context context = this;


  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_food_list);
    ListAdapter adapter = new com.example.azaabudeen.restoapp.CustomListView(this,itemname);
    ListView listView= (ListView)findViewById(R.id.listview);
    ListView secondlistview= (ListView)findViewById(R.id.foodlistBuyButton);
    ListAdapter secondA= new ArrayAdapter<String>(this,安卓.R.layout.simple_list_item_1,buy);
    secondlistview.setAdapter(secondA);
    listView.setAdapter(adapter);

    final Dialog dialog = new Dialog(context);
    dialog.setContentView(R.layout.view);

    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            String currentItem= String.valueOf(parent.getItemAtPosition(position));
            Toast.makeText(list_activity.this,currentItem,Toast.LENGTH_SHORT).show();

         ///   final TextView text = (TextView)findViewById(R.id.text);
          ///  final Button myButton=(Button)findViewById(R.id.dialogButtonOK);
           /// text.setText("Image of the list");
           /// myButton.setOnClickListener(new View.OnClickListener() {
              ///  @Override
               /// public void onClick(View v) {
                 ////   dialog.dismiss();
               // }
           /// });
            dialog.show();
        }
    });
  }
}

更新:
我通过向Customadapter单独添加onClickListners实现了这一点 这是密码

class CustomListView extends ArrayAdapter {
  public CustomListView(Context context, String[] resource) {
    super(context,R.layout.custom_view , resource);
  }

  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    LayoutInflater MyInflater = LayoutInflater.from(getContext());
    View CustomView = MyInflater.inflate(R.layout.custom_view, parent, false);
    String SingleItem= (String) getItem(position);
    TextView text =(TextView)CustomView.findViewById(R.id.Itemname);
    ImageView Image= (ImageView)CustomView.findViewById(R.id.icon);

    text.setText(SingleItem);
    Image.setImageResource(R.drawable.myimage);
    final Button Buybutton= (Button)CustomView.findViewById(R.id.BuyButton);
    Buybutton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Toast.makeText(getContext(), "Bought", Toast.LENGTH_SHORT).show();
        }
    });


    Image.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Toast.makeText(getContext(),"Image",Toast.LENGTH_SHORT).show();

        }
    });
    return CustomView;
  }
} 

共 (0) 个答案