2017-03-03 84 views
0

我正在使用带有文本视图的自定义列表视图。当单击文本视图时,必须根据可用文本增加行高。例如,当holder.asr_tv_Content按下当前行,在那里与其他控件高度具有沿按压以增大在android自定义列表视图中展开textview高度

public class StudentRemarksAdapter extends BaseAdapter { 

     Context _Context = null; 
     ArrayList<String> _as_Day; 
     ArrayList<String> _as_Month; 
     ArrayList<String> _as_Year; 
     ArrayList<String> _as_Heading; 
     ArrayList<String> _as_Content; 
     ArrayList<String> _as_Values; 
     LayoutInflater inflater = null; 

     public StudentRemarksAdapter(Context a_Context, 
       ArrayList<String> as_Day, ArrayList<String> as_Month, 
       ArrayList<String> as_Year, ArrayList<String> as_Heading, 
       ArrayList<String> as_Content, ArrayList<String> as_Values) { 
      // TODO Auto-generated constructor stub 
      this._Context = a_Context; 

      this._as_Day = as_Day; 
      this._as_Month = as_Month; 
      this._as_Year = as_Year; 
      this._as_Heading = as_Heading; 
      this._as_Content = as_Content; 
      this._as_Values = as_Values; 
      inflater = (LayoutInflater) _Context 
        .getSystemService(Context.LAYOUT_INFLATER_SERVICE); 

     } 

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

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

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

     public class Holder { 
      RelativeLayout asr_rl_background; 
      TextView asr_tv_Day, asr_tv_Month, asr_tv_Year, asr_tv_Heading, 
        asr_tv_Content; 

     } 

     @Override 
     public View getView(final int position, View convertView, 
       ViewGroup parent) { 
      // TODO Auto-generated method stub 
      Holder holder = new Holder(); 
      if (convertView == null) { 
       holder = new Holder(); 

       convertView = inflater.inflate(R.layout.adapter_studentremarks, 
         null); 

       holder.asr_rl_background = (RelativeLayout) convertView 
         .findViewById(R.id.asr_rl_background); 

       holder.asr_tv_Day = (TextView) convertView 
         .findViewById(R.id.asr_tv_Day); 
       setControlsStyle 
         .SetCustomTextViewStyleForContent(holder.asr_tv_Day); 

       holder.asr_tv_Month = (TextView) convertView 
         .findViewById(R.id.asr_tv_Month); 
       setControlsStyle 
         .SetCustomTextViewStyleForContent(holder.asr_tv_Month); 

       holder.asr_tv_Year = (TextView) convertView 
         .findViewById(R.id.asr_tv_Year); 
       setControlsStyle 
         .SetCustomTextViewStyleForContent(holder.asr_tv_Year); 

       holder.asr_tv_Heading = (TextView) convertView 
         .findViewById(R.id.asr_tv_Heading); 
       setControlsStyle 
         .SetCustomTextViewStyleForContentWithBlackText(holder.asr_tv_Heading); 

       holder.asr_tv_Heading.setTextSize(18); 
       holder.asr_tv_Heading.setGravity(Gravity.CENTER | Gravity.LEFT); 

       holder.asr_tv_Content = (TextView) convertView 
         .findViewById(R.id.asr_tv_Content); 
       setControlsStyle 
         .SetCustomTextViewStyleForContentWithBlackText(holder.asr_tv_Content); 
       holder.asr_tv_Month.setTextSize(14); 
       holder.asr_tv_Year.setTextSize(14); 

       holder.asr_tv_Content.setGravity(Gravity.TOP | Gravity.LEFT); 
       convertView.setTag(holder); 
      } 

      else { 
       holder = (Holder) convertView.getTag(); 
      } 

      holder.asr_tv_Day.setText(_as_Day.get(position)); 
      holder.asr_tv_Day.setTextSize(26); 

      holder.asr_tv_Month.setText(_as_Month.get(position)); 

      holder.asr_tv_Year.setText(_as_Year.get(position)); 

      holder.asr_tv_Heading.setText(_as_Heading.get(position)); 
      holder.asr_tv_Content.setText(_as_Content.get(position)); 



      if (_as_Values.get(position).equals(
        _Context.getResources() 
          .getStringArray(R.array.as_mode_Text)[0])) { 
       holder.asr_rl_background.setBackgroundColor(_Context 
         .getResources().getColor(
           R.color.asr_tv_positiveicon_bgcolor)); 
      } else { 
       holder.asr_rl_background.setBackgroundColor(_Context 
         .getResources().getColor(
           R.color.asr_tv_negativeicon_bgcolor)); 
      } 

      return convertView; 
     } 
    } 
+0

为什么不是所有那些浪费的列表而是一个单独的'ArrayList mRemarks;'。此外,避免挂在上下文,除非关键 –

回答

0

设置视图高度WRAP_CONTENT(和做同样为它的祖先)

当告诉你默认的文本,显示它的一小部分

private static final int MAX_LEN = 22; //choose this yourself 

if (text.length() > MAX_LEN) { 
    textView.setText(text.substring(0, MAX_LEN) + "..."); 
} else { 
    textView.setText(text); 
} 

随后的onClick,与全价值

再次更新
+0

嗨,谢谢你的答复。 – user3211432

+0

如何仅更改当前按下的行。 – user3211432

+0

*会*只会改变当前行 –