我很难让LayoutInflater按预期工作,其他人也是如此:如何使用layoutinflator在运行时添加视图?.
为什么LayoutInflater会忽略我指定的布局参数?例如,为什么我的资源XML中的值layout_width和layout_height值不受尊重?
Avoid passing null as the view root当用nullas 膨胀视图时,我得到了lint警告parent,例如:
LayoutInflater.from(context).inflate(R.layout.dialog_edit, null);
Run Code Online (Sandbox Code Playgroud)
但是,视图是用作一个内容AlertDialog,使用setViewon AlertDialog.Builder,所以我不知道应该传递什么parent.
parent在这种情况下你认为应该是什么?
当我使用弹出窗口显示时,我希望能够模糊或调暗背景popup.showAtLocation,并在popup.dismiss调用时将背景解开/调暗.
我曾尝试应用布局PARAMS FLAG_BLUR_BEHIND和FLAG_DIM_BEHIND我的活动,但这似乎只是一旦我的应用程序开始模糊和朦胧的背景.
如何使用弹出框进行模糊/调光?
我想写一个ListView基本格式,但我收到一个错误:
UnsupportedOperationException: addView(View, LayoutParams) is not supported in AdapterView
Run Code Online (Sandbox Code Playgroud)
和:
androidview.LayoutInfalater.inflate(LayoutInflater.java: some numbers....like 720,658...so on)
Run Code Online (Sandbox Code Playgroud)
我知道应该在适配器类中完成一些事情:
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
RelativeLayout rv = new RelativeLayout(c);
TextView tv = new TextView(c);
TextView tv1 = new TextView(c);
ImageView imgv = new ImageView(c);
tv.setText(s[position]);
tv1.setText(i[position]);
imgv.setImageResource(d[position]);
rv.addView(tv);
rv.addView(tv1);
rv.addView(imgv);
return rv;
}
Run Code Online (Sandbox Code Playgroud)
我该怎么做才能解决问题
LOGCAT:
02-20 16:40:24.967: E/Trace(1715): error opening trace file: No such file or directory (2)
02-20 16:40:25.819: W/ResourceType(1715): No …Run Code Online (Sandbox Code Playgroud) 我TextView的每个列表项都有多个s ListView.我已经学会了写一个getView我认为合适的方法,但我不确定我是否会使用setAdapter这种方法.
private static String[] project = {"proj1","proj2"};
private static String[] workRequests = {"requirement gathering", "design"};
private static String[] startDate = {"02/21/2012","07/15/2011"};
private static String[] status = {"WIP","DONE"};
ListView mListView;
public class MyDashboardActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mydashboard);
final LayoutInflater mInflater = LayoutInflater.from(this);
mListView = (ListView)findViewById(R.id.dashboardList);
mListView.setAdapter(
// How do I set the adapter?
);
}
public View getView(int position, View convertView, ViewGroup parent) {
System.out.println("enters");
if(convertView …Run Code Online (Sandbox Code Playgroud) 我正在使用net上发现的Expandable ListView示例
活动:
public class ExpandableListViewActivity extends ExpandableListActivity {
/**
* strings for group elements
*/
static final String arrGroupelements[] = { "India", "Australia", "England",
"South Africa" };
/**
* strings for child elements
*/
static final String arrChildelements[][] = {
{ "Sachin Tendulkar", "Raina", "Dhoni", "Yuvi" },
{ "Ponting", "Adam Gilchrist", "Michael Clarke" },
{ "Andrew Strauss", "kevin Peterson", "Nasser Hussain" },
{ "Graeme Smith", "AB de villiers", "Jacques Kallis" } };
DisplayMetrics metrics;
int width;
ExpandableListView expList;
@Override …Run Code Online (Sandbox Code Playgroud) 在我的Android应用程序中,我创建了一个这样的对话框:
private void handleEdit() {
LayoutInflater inflater = getLayoutInflater();
View dialoglayout = inflater.inflate(R.layout.dialog_gallery, null);
final AlertDialog d = new AlertDialog.Builder(this)
.setView(dialoglayout)
.setTitle(R.string.edit)
.setNegativeButton(R.string.cancel, null)
.create();
CheckBox mainCB = (CheckBox)dialoglayout.findViewById(R.id.main);
CheckBox usedCB = (CheckBox)dialoglayout.findViewById(R.id.used);
mainCB.setChecked(image.getIsMain());
usedCB.setChecked(image.getApproved());
mainCB.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
if (Network.isNetworkAvailable(GalleryScreen.this)) {
new Async_update_image_state(GalleryScreen.this, fish, image, !image.getIsMain(), image.getApproved(), false);
d.dismiss();
} else {
Popup.ShowErrorMessage(GalleryScreen.this, R.string.no_internet, false);
}
}
});
usedCB.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
if (Network.isNetworkAvailable(GalleryScreen.this)) {
new Async_update_image_state(GalleryScreen.this, fish, image, …Run Code Online (Sandbox Code Playgroud)