问题1:LinearLayout cannot resolved to a type
Button cannot resolved to a type
TextView cannot resolved to a type
解决方案:
import android.widget.*;
问题2:LayoutParams cannot be resolved to a type
解决方案:new ViewGroup.LayoutParams
Button cannot resolved to a type
TextView cannot resolved to a type
解决方案:
import android.widget.*;
问题2:LayoutParams cannot be resolved to a type
解决方案:new ViewGroup.LayoutParams
package org.crazyit.ui;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.*;
public class CodeView extends Activity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
LinearLayout layout = new LinearLayout(this);
super.setContentView(layout);
layout.setOrientation(LinearLayout.VERTICAL);
final TextView show = new TextView(this);
Button bn = new Button(this);
bn.setText(R.string.ok);
bn.setLayoutParams(new ViewGroup.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT));
layout.addView(show);
layout.addView(bn);
bn.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
show.setText("Hello , Android , " + new java.util.Date());
}
});
}
}