我有一些线性布局的TextViews,EditTexts和Buttons。如果我触摸/单击LinearLayout的任何一侧,它将转到下一个活动。我已经尝试为LinearLayout中的所有元素设置onClick侦听器。这有效但有没有办法编写代码来触摸LinearLayout的任何区域以进行下一个活动而无需为所有元素添加onClick处理程序?因为布局中有更多元素。请帮助我。
答案 0 :(得分:0)
尝试从代码中为linerlayout设置onClick listener事件,如下所示
LinearLayout l1 = (LinearLayout)findViewById(R.id.layout1);
l1.setOnClickListener(this);
l1.setClickable(true);
答案 1 :(得分:0)
试试这个。
login.java
package com.android;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class Login extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button newuser = (Button) findViewById(R.id.Button02);
newuser.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent myIntent = new Intent(view.getContext(), Register.class);
startActivityForResult(myIntent, 0);
}
});
}
}
Register.java
package com.android;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class Register extends Activity {
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.register);
Button register = (Button) findViewById(R.id.Button03);
register.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent intent = new Intent();
setResult(RESULT_OK, intent);
finish();
}
});
}}