android 可扩展列表需要帮助
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
View v = null;
if( convertView != null )
v = convertView;
else
v = inflater.inflate(R.layout.child_row, parent, false);
Color c = (Color)getChild( groupPosition, childPosition );
TextView color = (TextView)v.findViewById( R.id.childname );
if( color != null )
color.setText( c.getColor() );
TextView rgb = (TextView)v.findViewById( R.id.rgb );
if( rgb != null )
rgb.setText( c.getRgb() );
// CheckBox cb = (CheckBox)v.findViewById( R.id.check1 );
// cb.setChecked( c.getState() );
Button btnPlay=(Button)v.findViewById(R.id.Play);
Button btnDelete=(Button)v.findViewById(R.id.Delete);
Button btnEmail=(Button)v.findViewById(R.id.Email);
btnPlay.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
Log.i("TEST ", "play btn cliked");
Intent i=new Intent(this,FindFilesByType.class);//THIS IS NOT ALLOWED IN MY CODE
}
});
return v;
}
在上面的代码中,我编写了我的适配器类。 我小时候的可解释列表中有 3 个按钮。 我想在按钮的单击事件上调用另一个Java类, 所以,当我使用:
Intent i=new Intent(this,FindFilesByType.class);
我得到这个:
The constructor Intent(new View.OnClickListener(){}, Class<FindFilesByType>) is undefined
Remove arguments to match 'Intent'
我正在做的事情出了什么问题?
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
View v = null;
if( convertView != null )
v = convertView;
else
v = inflater.inflate(R.layout.child_row, parent, false);
Color c = (Color)getChild( groupPosition, childPosition );
TextView color = (TextView)v.findViewById( R.id.childname );
if( color != null )
color.setText( c.getColor() );
TextView rgb = (TextView)v.findViewById( R.id.rgb );
if( rgb != null )
rgb.setText( c.getRgb() );
// CheckBox cb = (CheckBox)v.findViewById( R.id.check1 );
// cb.setChecked( c.getState() );
Button btnPlay=(Button)v.findViewById(R.id.Play);
Button btnDelete=(Button)v.findViewById(R.id.Delete);
Button btnEmail=(Button)v.findViewById(R.id.Email);
btnPlay.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
Log.i("TEST ", "play btn cliked");
Intent i=new Intent(this,FindFilesByType.class);//THIS IS NOT ALLOWED IN MY CODE
}
});
return v;
}
In the code above, I've written my adapterclass.
There are 3 buttons in my explandable list as a child.
I want to call another Java class on button's click event,
so, when I am using:
Intent i=new Intent(this,FindFilesByType.class);
I am getting this:
The constructor Intent(new View.OnClickListener(){}, Class<FindFilesByType>) is undefined
Remove arguments to match 'Intent'
What is wrong with what I am doing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Intent 构造函数中的
this
对象是匿名 OnClickListener 类实例,而不是当前上下文。您需要做的是在该构造函数中使用当前上下文,例如:The
this
object in your Intent constructor is the anonymous OnClickListener class instance, as opposed to your current context. What you need to do is to use the current context in that constructor like:首先,在 onCreate() 方法之前创建实例变量,例如
并在单击事件时在您的孩子中调用该变量
希望这可以有所帮助。
At the start, create intance variable before onCreate() method like
And called that variable in your child on click event
Hope this can help.
将上述方法添加到适配器类中,这对我来说是完全有效的代码:)
this above methos into the adapter class this is fully working code for me :)