标签: layout-inflater

Android:如何动态更改膨胀的标签内容?

我在从XML文件中填充的选项卡上设置内容时遇到问题.

我通过执行以下操作动态地将选项卡添加到我的TabHost('tabs'):

        TabSpec passSpec = tabs.newTabSpec("Pass Tab"); 
        passSpec.setIndicator("Passengers", getResources().getDrawable(R.drawable.tab_message));

        passSpec.setContent(new TabHost.TabContentFactory() { 
            public View createTabContent(String tag) { 
                View layout = mInflater.inflate(R.layout.tab_content_passengers, null);                 
                return(layout); 
            } 
        });
        tabs.addTab(passSpec);
Run Code Online (Sandbox Code Playgroud)

这很好用......我遇到的问题是稍后更改该选项卡上的内容.有没有办法实现这一点,而不用全新的布局重新膨胀所有选项卡?

我正在尝试以下内容并且没有任何反应:

    mInflater = LayoutInflater.from(this);
    View layout = mInflater.inflate(R.layout.tab_content_passengers, null);
    TextView t = (TextView) layout.findViewById(R.id.testText);
    t.setText("Hello world??");
Run Code Online (Sandbox Code Playgroud)

android android-tabhost layout-inflater

5
推荐指数
1
解决办法
4282
查看次数

android.view.InflateException:二进制XML文件行#7:错误类膨胀

尝试运行我的项目时收到错误消息.我想为Android创建Tic Tac Toe,我使用下面的自定义View来创建Tic Tac Toe板:

package org.me.TicTacToe.ui;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.view.MotionEvent;
import android.view.View;

public class TicTacToeBoard extends View {

    private Tile[][] tile = null;   //Abstract class to create tiles in Tic Tac Toe Board
    int boardWidth = 3; //It mean Tic Tac Toe board is consists of 3x3 tiles
    private int width;
    private int height;
    private Paint brush;

    public TicTacToeBoard(Context context) {
        super(context);

        brush = new Paint();
        this.brush.setARGB(255, 0, 0, 0);
        this.brush.setAntiAlias(true);
        this.brush.setStyle(Style.STROKE);
        this.brush.setStrokeWidth(5); …
Run Code Online (Sandbox Code Playgroud)

android layout-inflater

5
推荐指数
1
解决办法
2万
查看次数

Android:自定义适配器与自定义微调器下拉xml布局给出错误

我有一个带有自定义适配器的微调器,我用它来设置微调器中第一个元素的高度下降到零.我这样做是为了在我的微调器(第一个元素)中有一个默认消息,而用户无法单击它,因为它不可见.

package org.digitalhealthagency.elaj.util;

import java.util.ArrayList;

import org.digitalhealthagency.elaj.gui.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.SpinnerAdapter;
import android.widget.TextView;

public class CustomAdapter extends ArrayAdapter implements SpinnerAdapter{

    Context context;
    int textViewResourceId;
    ArrayList arrayList;

    public CustomAdapter(Context context, int textViewResourceId,  ArrayList arrayList) {
        super(context, textViewResourceId, arrayList);

        this.context = context;
        this.textViewResourceId = textViewResourceId;
        this.arrayList = arrayList;

    }

    @Override
     public View getDropDownView(int position, View convertView, ViewGroup parent){
       if (convertView == null)
       {
         LayoutInflater vi = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
         //convertView = vi.inflate(android.R.layout.simple_spinner_dropdown_item, null);
         convertView = …
Run Code Online (Sandbox Code Playgroud)

android spinner layout-inflater custom-adapter

5
推荐指数
1
解决办法
1万
查看次数

运行时Android上的重复视图

我为活动创建了一个布局文件.在这个布局中,我创建了一个带有textview和edittext的LinearLayout.现在我想创建额外的LinearLayouts,它将查看并包含与原始LinearLayout完全相同的视图,但具有不同的文本.我还想在运行期间以编程方式执行此操作,因为这些LinearLayout的数量在运行之间会有所不同.我已经阅读了一些关于inflaters的内容,但我对它们的理解并不充分.

我在想这样的事情,显然代码是错误的,但希望你明白我想做什么:

LinearLayout llMain = (LinearLayout)findViewById(R.id.mainLayout);
LinearLayout llToCopy = (LinearLayout)findViewById(R.id.linearLayoutToCopy);
for(int player = 0; player < size; player++)
{
   LinearLayout llCopy = llToCopy.clone();
   TextView tv = (TextView)llCopy.getChildAt(0);
   tv.setText(players.get(player).getName());
   llMain.addView(llCopy);
}
Run Code Online (Sandbox Code Playgroud)

android view layout-inflater

5
推荐指数
2
解决办法
1万
查看次数

向FootView添加页脚后崩溃

我正在尝试添加页脚,ListView但是在这行代码之后应用程序崩溃:getListView().addView(footerView);.我是android的新手,这是我第一次体验ListView.

如果可能的话我需要简短解释膨胀方法.

谢谢!

  ToDoListAdapter mAdapter;

        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);

            // Create a new TodoListAdapter for this ListActivity's ListView
            mAdapter = new ToDoListAdapter(getApplicationContext());

            // Put divider between ToDoItems and FooterView
            getListView().setFooterDividersEnabled(true);

            //TODO - Inflate footerView for footer_view.xml file
            TextView footerView = (TextView) getLayoutInflater().inflate(R.layout.footer_view, null);

            //TODO - Add footerView to ListView
            getListView().addView(footerView);

            footerView.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {

                    log("Entered footerView.OnClickListener.onClick()");

                    //TODO - Attach Listener to FooterView. Implement onClick().
                    Intent startNewActivity …
Run Code Online (Sandbox Code Playgroud)

android listview layout-inflater

5
推荐指数
1
解决办法
5783
查看次数

在多个膨胀的EditTexts上设置文本会导致在旋转后使用相同的文本填充所有文本

我正在膨胀一些EditTexts并将它们添加到LinearLayout:

private void setupCommentViews(){
    int i = 0;
        Iterator<CommentInformation> iterator = commentInformations.iterator();
    while(iterator.hasNext()) {
            i++;
            View v = LayoutInflater.from(context).inflate(R.layout.comment_row_item, commentsContainer, false);

            EditText commentField = (EditText)v.findViewById(R.id.comment);         

            CommentInformation commentInformation = iterator.next();
            final String uniqueId = commentInformation.getUniqueId();

            String currentCommentText = comments.get(uniqueId);         
            if(currentCommentText != null) {
                Log.v("into","Setting old text: "+currentCommentText);
                commentField.setText(currentCommentText);
            } else {
                Log.v("into","Setting empty text: "+i);
                commentField.setText("Setting empty text: "+i);
            }


            commentField.addTextChangedListener(new TextWatcher() {

                @Override
                public void onTextChanged(CharSequence s, int start, int before, int count) {
                }

                @Override …
Run Code Online (Sandbox Code Playgroud)

android android-layout screen-rotation android-edittext layout-inflater

5
推荐指数
1
解决办法
1198
查看次数

如何使用RecyclerView,尝试遵循developer.android.com建议,但得到错误

我正在尝试使用RecyclerView来显示我的数据集,尝试关注此网站 https://developer.android.com/training/material/lists-cards.html

问题是有一些部分是错误的,无法找到如何解决它,我确切地说该网站的建议.

public class MyAdapter extends RecyclerView.Adapter<MyAdapter.ViewHolder> {
    private String[] mDataset;

    // Provide a reference to the views for each data item
    // Complex data items may need more than one view per item, and
    // you provide access to all the views for a data item in a view holder
    public static class ViewHolder extends RecyclerView.ViewHolder {
        // each data item is just a string in this case
        public TextView mTextView;
        public ViewHolder(TextView v) {
            super(v);
            mTextView = …
Run Code Online (Sandbox Code Playgroud)

android android-adapter layout-inflater android-viewholder android-recyclerview

5
推荐指数
1
解决办法
1330
查看次数

配置更改后如何在android中保存膨胀的布局?

我创建了一个应用程序,LinearLayout每次按下按钮时我都会动态添加和删除textView .

我的问题是,当屏幕方向改变,重新启动活动时,添加的所有textViews都会消失.我不知道如何保持LinearLayout膨胀状态.

这是我初始化视图和按钮的代码的一部分:

private LayoutInflater inflater;
private LinearLayout ll;
View view;
Button add;
Button delete;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    inflater = getLayoutInflater();
    ll = (LinearLayout)findViewById(R.id.ll);
    add = (Button)findViewById(R.id.bAdd);
    delete = (Button)findViewById(R.id.bDelete);

    add.setOnClickListener(this);
    delete.setOnClickListener(this); 
Run Code Online (Sandbox Code Playgroud)

onClick我添加或删除textViews的方法上:

 @Override
    public void onClick(View v) {
        switch (v.getId())
        {
            case R.id.bAdd:
            {
                view = inflater.inflate(R.layout.sublayout,ll,true);
                break;
            }
            case R.id.bDelete:
            {
                int childSize = ll.getChildCount();
                if(0 != childSize) {
                    ll.removeViewAt(childSize -1);
                }
                Log.i("InflateLayout", "childsize: " +childSize); …
Run Code Online (Sandbox Code Playgroud)

android layout-inflater

5
推荐指数
1
解决办法
463
查看次数

LayoutInflater异常

这是交易,我有一个扩展布局的RecycleView适配器onCreateViewHolder.当我尝试执行以下操作时:

  1. 应用创建没有任何问题
  2. 进入多任务窗口
  3. 回到应用程序
  4. InflateException

Fresco的SimpleDraweeView出现错误,它以xml定义.

<com.facebook.drawee.view.SimpleDraweeView
        android:id="@+id/photo"
        android:layout_width="match_parent"
        android:layout_height="@dimen/image_nobar"
        android:layout_alignParentEnd="true"
        android:layout_alignParentStart="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:adjustViewBounds="true"
        android:contentDescription="@string/photo"
        fresco:placeholderImage="@drawable/fry"
        fresco:actualImageScaleType="focusCrop" />
Run Code Online (Sandbox Code Playgroud)

这就是我将适配器设置为RecycleView的方法

list = new ArrayList<>();
gagInfo gi = new gagInfo();
list.add(gi.setEmpty());
recList.setAdapter(new gagAdapter(list, context));
populateRecyclerView(recList);
Run Code Online (Sandbox Code Playgroud)
private void populateRecyclerView(final RecyclerView rView) {

    new Thread(new Runnable() {
        @Override
        public void run() {
            SharedPreferences prefs = getSharedPreferences(GAGS, MODE_PRIVATE);

            Map<String, ?> allEntries = prefs.getAll();
            list = new ArrayList<>();
            JSONObject obj;
            String keyObject;
            Boolean first = true;
            for (Map.Entry<String, ?> entry : …
Run Code Online (Sandbox Code Playgroud)

java android exception layout-inflater fresco

5
推荐指数
1
解决办法
454
查看次数

创建Activity是否比创建片段更快?

我有一个布局Fragment的创建过程中,显示有关产品,但遗憾的是资料,fragment一点滞后(毛刺)约50毫秒(这是我猜的滞后如何记录是这是一个很大的刷新率(Android版) 16毫秒),但是当我Activity 直接使用相同的布局并应用相同的逻辑时,它看起来和感觉都很平滑。

这种情况有什么特殊原因吗?有什么方法可以使片段在创建过程中看起来像活动一样平滑吗?

您可以测试一些复杂的布局,然后尝试将其作为片段的视图充气,并与活动的布局内容相同。

这是我的oncreate在片段和活动中的样子:

@Override
public void onCreate ( Bundle savedInstanceState ) {  // or equivalent  override for fragment.
    super.onCreate ( savedInstanceState );
    setContentView ( R.layout.fragment_product_profile );
    initLayout ();
    loadData ();
    initCustomMadeImageSlider ();
    autoScrollViewPager ();
}
Run Code Online (Sandbox Code Playgroud)

这是关于UI的一般想法

android android-layout android-fragments layout-inflater android-activity

5
推荐指数
1
解决办法
1062
查看次数