2016-04-05 12 views
1

私は2つのリストビューを持っています。私は2つのリストビューを同時にスクロールさせたい

1つはimageviewとtextview insdieのカスタムリストビューで、もう1つはスクロールの解決策を見つけた後のボタンです。

基本的に左は食べ物とその写真のリスト、右は買うためのリストです。
今私は同時にそれらをスクロールする際に問題があります。

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,android.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を追加することによって、それをしなかったあなただけの1 ListViewを使用する必要があり、コード

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

両方の画像を同時にスクロールしたい場合は、同じリストビューに画像とボタンを置くのが簡単でしょうか? –

+0

最初のリストビューをクリックすると他の作業が必要になります。たとえば、画像をクリックすると、フルスクリーンにプロンプ​​トが表示され、ボタンをクリックすると他の作業が行われます。 –

+0

@SarmadAijazを実現できます1つのリストビューのみを使用して目的の機能を使用することはできません.2つのリストビューが必要です – Dhiraj

答えて

1

です。

onClickListenerをカスタムアダプターの中に設定することができます。

例はここにある:あなたのImageViewのためにとあなたのボタンのListView with clickListener

設定onClickListener

関連する問題