Jed*_*Jed 1 java android constructor
这是我要去的班级
public class AxxessCCPAccountDetails extends Activity {
public AxxessCCPAccountDetails(String username) {
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.accountdetails);
}
Run Code Online (Sandbox Code Playgroud)
}
这是我传递的代码
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// When clicked, show a toast with the TextView text
Toast.makeText(getApplicationContext(), ((TextView) view).getText(),
Toast.LENGTH_SHORT).show();
Intent myIntent = new Intent(view.getContext(), AxxessCCPAccountList.class);
startActivityForResult(myIntent, 0);
}
});
Run Code Online (Sandbox Code Playgroud)
我需要将用户名传递给一个类.我如何将该参数传递给该类,然后激活链接到视图的活动(类).
谢谢
用Intent.您不应该为Activity该类创建自己的构造函数.
这是一个简短的例子:
Intent myIntent = new Intent(view.getContext(), AxxessCCPAccountList.class);
myIntent.putExtra("username", userName);
myIntent.putExtra("pass", pass);
Run Code Online (Sandbox Code Playgroud)
然后,在你的AxxessCCPAccountList.onCreate方法中:
String userName = this.getIntent().getStringExtra("username");
String pass = this.getIntent.getStringExtra("pass");
Run Code Online (Sandbox Code Playgroud)