0

我想跳进一个班级,用户输入数字。我试过这个:

EditText eTinput;
 int n;
n=eTinput.getText().toString;


@Override
public void onClick(View v) {
    // TODO Auto-generated method stub

    try {
        Class ourClass    =Class.forName("com.dvdroid.kannadavachanagalu.Shareb",+n);
        Intent ourintent = new Intent(BasavaSelect.this, ourClass);
        startActivity(ourintent);
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    }
}
});

但是我收到一些错误,因为“将输入 n 更改为可编辑”和“删除参数以匹配 forname”

任何人都可以帮助如何做到这一点?

4

3 回答 3

0
    EditText eTinput;
    eTinput = (EditText)findViewById(R.id.yourEdittextIdFromXml);

@Override
public void onClick(View v) {
    // TODO Auto-generated method stub

    try {

        if(n==urvaluetocheck)
{

        Intent ourintent = new Intent(BasavaSelect.this, ourClass);
        startActivity(ourintent);

}

else if(n==urvaluetocheck)
{

        Intent ourintent = new Intent(BasavaSelect.this, classuwant);
        startActivity(ourintent);
}
..........

else
{

        Intent ourintent = new Intent(BasavaSelect.this, defaultclass);
        startActivity(ourintent);
}

    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    }
}
});
于 2013-11-15T08:06:01.247 回答
0

尝试如下:

EditText eTinput;
 int n;
n=eTinput.getText().toString;


@Override
public void onClick(View v) {
    // TODO Auto-generated method stub

    try {
        Class ourClass=Class.forName("com.dvdroid.kannadavachanagalu.Shareb");//Change this line
        Intent ourintent = new Intent(BasavaSelect.this, ourClass);
         ourintent.putExtra("Value", n); 
        startActivity(ourintent);
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    }
}
});
于 2013-11-15T08:09:01.507 回答
0

用这个:

eTinput = (EditText)findViewById(R.id.yourEdittextIdFromXml);
于 2013-11-15T08:09:28.883 回答