2013-06-07 3 views
0

View를 재정 의하여 CustomAdapter 클래스에서 텍스트 색상을 설정하려고합니다. 코드가 실행되는 것처럼 보이지만 전화 화면에는 아무 것도 표시되지 않습니다. 어떤 제안?CustomAdapter 뷰 오버라이드 설정 텍스트가 지정되지 않음

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

    prefs = PreferenceManager.getDefaultSharedPreferences(LogCat.this); 

    String logLevel = prefs.getString("dirLogCat", ""); 

    setContentView(R.layout.log_cat); 
    ListView lv1 = (ListView) findViewById(R.id.listView1); 


    ArrayAdapter<String> arrayAdapter = 
         new ArrayAdapter<String>(this, R.layout.text_list, log); 

    try { 
     Process process = Runtime.getRuntime().exec(new String[] {"logcat", "-d"}); 
     BufferedReader bufferedReader = new BufferedReader(
          new InputStreamReader(process.getInputStream())); 

     while ((line = bufferedReader.readLine()) != null){ 
      if (line.contains(" " + logLevel + " ")){ 
        //log.add(line); 
       log.add(line.substring(6, 14) + " " + line.substring(31, line.length())); 
      } 
     } 
    CustomAdapter adapter = new CustomAdapter(log, this, "V"); 
    lv1.setAdapter(arrayAdapter); 
    adapter.notifyDataSetChanged(); 
    } 
    catch (IOException e) {} 
} 


public class CustomAdapter extends BaseAdapter { 

    private Context ctx; 

    CustomAdapter (ArrayList<String> data, Context context, String log) { 
     this.ctx = context; 

     this.getView(0, new View(context), null); 
    } 

    @Override 
    public View getView(int position, View convertView, ViewGroup parent){ 
      LayoutInflater inflator = (LayoutInflater)ctx.getSystemService(LAYOUT_INFLATER_SERVICE); 
      View v = inflator.inflate(R.layout.text_list, null); 

      TextView textView = (TextView) v.findViewById(R.id.logText); 
      textView.setTextColor(Color.CYAN); 

      return textView; 
    } 

    @Override 
    public int getCount() { 
     // TODO Auto-generated method stub 
     return 0; 
    } 

    @Override 
    public Object getItem(int arg0) { 
     // TODO Auto-generated method stub 
     return null; 
    } 

    @Override 
    public long getItemId(int arg0) { 
     // TODO Auto-generated method stub 
     return 0; 
    } 
} 

}

편집 :

이 그것을했다 : 당신은 목록에서 잘못된 어댑터를 설정하는

public class CustomAdapter extends BaseAdapter { 

    private Context ctx; 
    private ArrayList<String> children; 

    CustomAdapter (ArrayList<String> data, Context context, String log) { 
     this.ctx = context; 
     System.out.println("Cyan1"); 
     this.children = data; 

     this.getView(0, new View(context), null); 
    } 

    @Override 
    public View getView(int position, View convertView, ViewGroup parent){ 
      LayoutInflater inflator = (LayoutInflater)ctx.getSystemService(LAYOUT_INFLATER_SERVICE); 
      View v = inflator.inflate(R.layout.text_list, null); 

      TextView textView = (TextView) v.findViewById(R.id.logText); 
      System.out.println("Cyan"); 
      textView.setTextColor(Color.CYAN); 
      for(int i = 0; i < log.size(); i++){ 
       textView.setText(children.get(i)); 
      } 
      return textView; 
    } 

답변

1

를?

CustomAdapter adapter = new CustomAdapter(log, this, "V"); 
lv1.setAdapter(arrayAdapter); //<---- arrayAdapter instead of adapter? 
adapter.notifyDataSetChanged(); 
+0

그럼 이제 텍스트가 있지만 대신 log''의 크기가 0을 반환, 당신은 또한'getCount()'방식을 수정해야하는 대신 나는 그것이 – ono

+0

아 .setTextColor 설정 무엇을 흰색입니다. – dmon

+0

return log.size()로 변경했습니다. 아직도 색깔 변화 없음. – ono

관련 문제