【发布时间】:2011-09-12 10:18:34
【问题描述】:
我是 android 的新开发人员。我在该视图类中创建了一个视图类我想将字符串数组值应用到 textview 我的视图类如下:
class MyView extends View
{
Context con;
String messages[]=new String[]{"hello","hai","how are you","where are you"};
public MyView(Context context) {
super(context);
con=context;
for(int i=0;i<3;i++)
{
Log.v("messages", "messages"+messages[i]);
}
public View getView(int position, View view, ViewGroup vg)
{
if (view == null)
{
// context would be a variable set via the constructor and given
// by our owner (most likely a ListActivity)
LayoutInflater inflater = (LayoutInflater)con.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(R.layout.view, null);
}
// Here you would get the sub-views of your layout and fill them
TextView msg = (TextView) view.findViewById(R.id.txtmessage);
msg.setText(messages[position]);
return view;
}
}
从上面的类中我想在活动类中查看 MyView 类的视图
public class ViewActivity extends Activity {
TableRow tbr;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.view);
tbr=(TableRow)findViewById(R.id.tableRow1);
MyView mv=new MyView(this);
tbr.addView(mv);
}
}
从上面的代码我无法查看 MyView 类
如何获得 MyView 类的视图
【问题讨论】:
标签: android view android-activity