我正在尝试在LinearLayout中获取视图以填充宽度.我尝试使用LayoutParams设置它,但它给了我一个错误:
我的代码:
EditText et = new EditText(v.getContext());
et.setHint("asset ");
et.setTextSize(12);
et.setLayoutParams(new LayoutParams(
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT, 0.25f));
et.setPadding(0, 15, 0, 10);
Run Code Online (Sandbox Code Playgroud)
错误 :
EditText et = new EditText(v.getContext());
et.setHint("asset ");
et.setTextSize(12);
et.setLayoutParams(new LayoutParams(
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT, 0.25f));
et.setPadding(0, 15, 0, 10);
Run Code Online (Sandbox Code Playgroud) 我需要创建一个包含一些视图的linearLayout,当单击一个按钮时,thsi按钮被另一个活动中的动作触发,所以我使用了performClick,但它似乎不起作用; 这是我的代码:
Button click = new Button(rootView.getContext());
SharedPreferences participant;
Editor editor;
SharedPreferences visible;
Editor vis;
participant = rootView.getContext().getSharedPreferences("participant", rootView.getContext().MODE_PRIVATE);
visible = rootView.getContext().getSharedPreferences("visible", rootView.getContext().MODE_PRIVATE);
editor = participant.edit();
final String name= participant.getString("key", "toto");
final String view = participant.getString("view","non");
if(view.equalsIgnoreCase("yes")) click.performClick();
click.setOnClickListener(new OnClickListener() {
@Override
public void onClick(final View v) {
// Creating a new LinearLayout
final LinearLayout ln = new LinearLayout(v.getContext());
// Setting the orientation to horizontal
ln.setOrientation(LinearLayout.HORIZONTAL);
formbis.addView(ln);
TextView tv1 = new TextView(v.getContext());
tv1.setText(name);
tv1.setTextSize(14);
tv1.setTypeface(null, Typeface.BOLD);
tv1.setPadding(0, 15, 0, 10); …Run Code Online (Sandbox Code Playgroud) 我正在使用一个方法:button_click(视图视图)在editText上设置文本,我有很多按钮,每个按钮都应该在特定的editText上设置文本.
有没有办法知道哪个按钮称为方法,以便我可以设置正确的editText文本?
这是方法的代码:
public void button_click(View view) {
// Create the dialog
final Dialog mDateTimeDialog = new Dialog(view.getContext());
// Inflate the root layout
LayoutInflater inflater = (LayoutInflater) view.getContext().getSystemService( Context.LAYOUT_INFLATER_SERVICE );
final RelativeLayout mDateTimeDialogView = (RelativeLayout) inflater.inflate(R.layout.datepick, null);
// Grab widget instance
final DateTimePicker mDateTimePicker = (DateTimePicker) mDateTimeDialogView
.findViewById(R.id.DateTimePicker);
mDateTimePicker.setDateChangedListener(this);
// Update demo edittext when the "OK" button is clicked
((Button) mDateTimeDialogView.findViewById(R.id.SetDateTime))
.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
mDateTimePicker.clearFocus();
// TODO Auto-generated method stub
String result_string = mDateTimePicker.getMonth()
+ …Run Code Online (Sandbox Code Playgroud)