2016-04-12 13 views
1

Çok sayıda Görüntüleme var (yaklaşık 30, daha fazla olabilir), kartlar gibi. Her biri için ClickListener öğesini ayarlıyorum, ancak çalışmıyor. Reaksiyon yok.Görüntülemeler için tıklayınListengörüntüler

protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_start); 
    final EditText searchProfile = (EditText) findViewById(R.id.search_profile); 
    final Button btnSearch = (Button) findViewById(R.id.btn_search); 
    final LinearLayout layoutProfileLeft = (LinearLayout) findViewById(R.id.layout_profiles_left); 
    searchProfile.setHint("UserName..."); 
    btnSearch.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      String profileName = searchProfile.getText().toString(); 
      urlForProfile = "http://www.dotabuff.com/search?utf8=&q=" + searchProfile.getText().toString().replace(" ", "+") + "&commit=Search"; 
      while (htmlSrc == "" || htmlSrc == null) { 
       setHtmlSrc(urlForProfile); 
      } 
      ArrayList<Integer> ids = new ArrayList<Integer>(); 
      for (int i = 0; i < 30; i++) { 
       searchedHeroes.add(i, new SearchedHero(i)); 
       RelativeLayout l = new RelativeLayout(StartActivity.this); 
       RelativeLayout.LayoutParams rlp = new RelativeLayout.LayoutParams(-1,-2); 
       rlp.setMargins(8, 0, 8, 8); 
       l.setLayoutParams(rlp); 
       l.setBackgroundColor(Color.rgb(69,90,100)); 
       l.setPadding(8,0,8,8); 
       l.setId(i); 
       //l.setLayoutParams(LinearLayout.); 
       ImageView img = new ImageView(StartActivity.this); 
       new DownloadImageTask(img).execute(searchedHeroes.get(i).getImageSrc()); 
       img.setOnClickListener(this); 
       img.setId(i + 40); 
       l.addView(img); 
       RelativeLayout innerL = new RelativeLayout(StartActivity.this); 
       RelativeLayout.LayoutParams paramsForInnerL = new RelativeLayout.LayoutParams 
         (-2, -2); 
       paramsForInnerL.addRule(RelativeLayout.RIGHT_OF, img.getId()); 
       TextView txtProfileName = new TextView(StartActivity.this); 
       txtProfileName.setText(searchedHeroes.get(i).getName()); 
       txtProfileName.setId(i + 80); 
       TextView txtLastMatch = new TextView(StartActivity.this); 
       txtLastMatch.setText(searchedHeroes.get(i).getLastMatch()); 
       txtProfileName.setTextSize(14); 
       txtProfileName.setTextColor(Color.WHITE); 
       txtLastMatch.setId(i + 120); 
       RelativeLayout.LayoutParams paramsForNameLastMatch = new RelativeLayout.LayoutParams 
         (
           RelativeLayout.LayoutParams.WRAP_CONTENT, 
           RelativeLayout.LayoutParams.WRAP_CONTENT 
         ); 
       innerL.addView(txtProfileName, rlp); 
       paramsForNameLastMatch.addRule(RelativeLayout.BELOW, txtLastMatch.getId()); 
       innerL.addView(txtLastMatch, paramsForNameLastMatch); 
       l.addView(innerL, paramsForInnerL); 
       l.setOnClickListener(this); 
       ids.add(i, l.getId()); 
       layoutProfileLeft.addView(l, rlp); 
       //} 
       //m.find(); 
       //passUrl = "http://www.dotabuff.com" + m.group(1); 
       //Intent pass = new Intent(StartActivity.this, MainActivity.class); 
       //pass.putExtra("EmpID", searchedHeroes.get(0).getProfileUrl()); 
       //startActivity(pass); 
       //} 
       //} 
      } 
     } 
    }); 
} 

@Override 
public void onClick(View v) { 
    Intent pass = new Intent(StartActivity.this, MainActivity.class); 
    pass.putExtra("Link", searchedHeroes.get(v.getId()).getProfileUrl()); 
    startActivity(pass); 
} 

Muhtemelen, her görünüm gerekir niyet diğer etkinlik: İşte benim kodudur. Teşekkürler.

tıklanabilir görüşlerinizi kurmayı unuttuğu geliyor bana
+0

l.setOnClickListener (StartActivity.this); – HenryChuang

+0

1. Neden? Finali kullanıyor musun? 2. Neden? İki OnClickListener kullanıyor musunuz? –

cevap

-1

: view.setClickable(true)

+0

Hala çalışmıyor. – bewusstlos

+0

A 'Düğmesi varsayılan olarak tıklanabilir. – codeMagic

+0

Bir şeyi özlemiş olabilirim ama hiçbir görüntü göremiyorum. Kısmen doğru olduğunuz halde, 'View' – codeMagic

-1
public class MainActivity extends Activity implements View.OnClickListener { 
EditText searchProfile; 
Button btnSearch; 
LinearLayout layoutProfileLeft 

protected void onCreate(Bundle savedInstanceState) { 
super.onCreate(savedInstanceState); 
setContentView(R.layout.activity_start); 
searchProfile = (EditText) findViewById(R.id.search_profile); 
btnSearch = (Button) findViewById(R.id.btn_search); 
layoutProfileLeft = (LinearLayout) findViewById(R.id.layout_profiles_left); 
searchProfile.setHint("UserName..."); 
btnSearch.setOnClickListener(this); 

} 

@Override 
public void onClick(View v) { 
Intent pass = new Intent(StartActivity.this, MainActivity.class); 
String profileName = searchProfile.getText().toString(); 
     urlForProfile = "http://www.dotabuff.com/search?utf8=&q=" + searchProfile.getText().toString().replace(" ", "+") + "&commit=Search"; 
     while (htmlSrc == "" || htmlSrc == null) { 
      setHtmlSrc(urlForProfile); 
     } 
     ArrayList<Integer> ids = new ArrayList<Integer>(); 
     for (int i = 0; i < 30; i++) { 
      searchedHeroes.add(i, new SearchedHero(i)); 
      RelativeLayout l = new RelativeLayout(StartActivity.this); 
      RelativeLayout.LayoutParams rlp = new RelativeLayout.LayoutParams(-1,-2); 
      rlp.setMargins(8, 0, 8, 8); 
      l.setLayoutParams(rlp); 
      l.setBackgroundColor(Color.rgb(69,90,100)); 
      l.setPadding(8,0,8,8); 
      l.setId(i); 
      //l.setLayoutParams(LinearLayout.); 
      ImageView img = new ImageView(StartActivity.this); 
      new DownloadImageTask(img).execute(searchedHeroes.get(i).getImageSrc()); 
      img.setOnClickListener(this); 
      img.setId(i + 40); 
      l.addView(img); 
      RelativeLayout innerL = new RelativeLayout(StartActivity.this); 
      RelativeLayout.LayoutParams paramsForInnerL = new RelativeLayout.LayoutParams 
        (-2, -2); 
      paramsForInnerL.addRule(RelativeLayout.RIGHT_OF, img.getId()); 
      TextView txtProfileName = new TextView(StartActivity.this); 
      txtProfileName.setText(searchedHeroes.get(i).getName()); 
      txtProfileName.setId(i + 80); 
      TextView txtLastMatch = new TextView(StartActivity.this); 
      txtLastMatch.setText(searchedHeroes.get(i).getLastMatch()); 
      txtProfileName.setTextSize(14); 
      txtProfileName.setTextColor(Color.WHITE); 
      txtLastMatch.setId(i + 120); 
      RelativeLayout.LayoutParams paramsForNameLastMatch = new RelativeLayout.LayoutParams 
        (
          RelativeLayout.LayoutParams.WRAP_CONTENT, 
          RelativeLayout.LayoutParams.WRAP_CONTENT 
        ); 
      innerL.addView(txtProfileName, rlp); 
      paramsForNameLastMatch.addRule(RelativeLayout.BELOW, txtLastMatch.getId()); 
      innerL.addView(txtLastMatch, paramsForNameLastMatch); 
      l.addView(innerL, paramsForInnerL); 
      l.setOnClickListener(this); 
      ids.add(i, l.getId()); 
      layoutProfileLeft.addView(l, rlp); 
     } 
pass.putExtra("Link", searchedHeroes.get(v.getId()).getProfileUrl()); 
startActivity(pass); 
} 
+0

sadece kod cevaplar tipik olarak SO için uygun değildir. * Neden * kodunuzun sorunu nasıl çözdüğü ve çözümlere katkıda bulunan herhangi bir faydalı bağlantıdan bahsederken nasıl farklı olduğu hakkında küçük bir açıklama eklemeyi düşünmelisiniz. – codeMagic

İlgili konular