cs x cs x - 7 months ago 101
Java Question

Can Android DataBinding use inner class?

UpdateActivity.java:

public class UpdateActivity extends Activity {

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

ActivityUpdateBinding dataBinding = DataBindingUtil.setContentView(this, R.layout.activity_update);
}

interface Listener {
void onClick(View v);
}
}


activity_update.xml:

<data>
<variable
name="listener"
type="com.kycq.reader.UpdateActivity$Listener"/>
</data>


if i set the 'listener',it always Errors.it is mean i can't set inner class,or i should set 'listener' on other way?

Answer

You can access inner classes using Android's data binding library as long as the inner class is declared public. I was able to use an inner class by making sure it was public. Instead of using com.kycq.reader.UpdateActivity$Listener use com.kycq.reader.UpdateActivity.Listener to access the inner class.