标签: setcontentview

SwipeRefreshLayout只能托管一个直接子项

我在listView中添加了"pull to refresh",我还想在列表为空时添加一个空视图 - 现在我收到了这个错误.我怎样才能做到这一点?如果我将一个视图定位在swipeRefresh之外,然后将其添加为emptyView它将起作用.那么我如何使用外部xml文件呢?

xml代码:

        <android.support.v4.widget.SwipeRefreshLayout
        android:id="@+id/swipeRefreshLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true" >


        <ListView
            android:id="@android:id/list"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:clipToPadding="false"
            android:paddingBottom="@dimen/inbox_vertical_margin" ></ListView>


</android.support.v4.widget.SwipeRefreshLayout>
Run Code Online (Sandbox Code Playgroud)

onCreateView:

View rootView = inflater.inflate(R.layout.fragment_inbox, container,
        false);

View empty = inflater.inflate(R.layout.empty_message_list, container,
        false);
ListView mListView = (ListView) rootView
        .findViewById(android.R.id.list);
((ViewGroup) mListView.getParent()).addView(empty);
TextView textViewToChange = (TextView) empty
        .findViewById(R.id.welcomeMessage);

textViewToChange.setText("YO "
        + ParseUser.getCurrentUser().getString(
                ParseConstants.KEY_PRESENTING_USERNAME)
        + "!  bad news.. :(");
mListView.setEmptyView(empty);

mSwipeRefreshLayout = (SwipeRefreshLayout) rootView
        .findViewById(R.id.swipeRefreshLayout);
mSwipeRefreshLayout.setOnRefreshListener(mOnRefreshListener);
mSwipeRefreshLayout.setColorScheme(R.color.swipeRefresh1,
        R.color.swipeRefresh2, R.color.swipeRefresh3,
        R.color.swipeRefresh4);

return rootView;
Run Code Online (Sandbox Code Playgroud)

xml android setcontentview

12
推荐指数
1
解决办法
6176
查看次数

Android:在更改布局时多次使用setContentView?

在更改布局时多次使用setContentView?

有人说这很糟糕,他们从不说明原因.

还有一些其他的东西要使用按钮更改布局吗?

android android-layout android-activity setcontentview

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

如何在使用AppCompat v22.1.0时在super.onCreate之前设置ContentView?

嘿,我刚刚将我的应用程序升级到AppCompat v22.1.0并得到了这个例外

Caused by: java.lang.IllegalArgumentException: AppCompat does not support the current theme features
        at android.support.v7.app.AppCompatDelegateImplV7.ensureSubDecor(AppCompatDelegateImplV7.java:360) 
        at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:246) 
        at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:106) 
Run Code Online (Sandbox Code Playgroud)

我找到了解决方案.这里/sf/answers/2085305001/

问题仍未解决,因为我在ConnectionWifiEditActivity类中的super.onCreate之后调用了setContentView .

当我改变它时,它会抛出NullPointerException 我如何解决这个问题?

Caused by: java.lang.NullPointerException
            at Client.Activity.connection.ConnectionEditActivity.onResume(ConnectionEditActivity.java:46)
            at Client.Activity.connection.ConnectionWifiEditActivity.onResume(ConnectionWifiEditActivity.java:81)
Run Code Online (Sandbox Code Playgroud)

ConnectionWifiEditActivity

public class ConnectionWifiEditActivity extends ConnectionEditActivity implements OnClickListener
{
    private ConnectionWifi connection;
    private EditText host;
    private EditText port;
    Button scan;
    ListView lv;
    private Toolbar mToolbar;

    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        this.setContentView(R.layout.connectionwifiedit);
        lv = (ListView) findViewById(android.R.id.list);
        this.connection = (ConnectionWifi) connectionParam;
        mToolbar = (Toolbar) findViewById(R.id.toolbar_actionbar);
        setSupportActionBar(mToolbar); …
Run Code Online (Sandbox Code Playgroud)

android android-appcompat setcontentview appcompatactivity

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

Drawable已经属于另一个所有者,但是没有公开恒定状态

错误:无效的可绘制对象已添加到LayerDrawable中!Drawable已经属于另一个所有者,但是没有公开恒定状态。

我今天突然注意到了这个错误,我不确定是否是因为我刚刚将测试设备更新为Android 8.0。该错误消息清楚地表明,在浮动操作按钮上设置波纹效果有问题,并且在按下按钮时确实没有波纹效果。但是,我不确定是什么导致了此问题。实际上,相同的错误连续两次抛出。任何帮助将非常感激!该应用程序的其余部分仍然可以正常运行,但该错误确实困扰着我。

ps minSdkVersion为22,targetSdkVersion和compiledSdkVersion为27

在MyActivity中,第117行是数据绑定和设置内容视图。

ActivityMyBinding binding = DataBindingUtil.setContentView(
            this, R.layout.activity_my);
Run Code Online (Sandbox Code Playgroud)

这是完整的堆栈跟踪:

W/LayerDrawable: Invalid drawable added to LayerDrawable! Drawable already belongs to another owner but does not expose a constant state.
             java.lang.RuntimeException
                 at android.graphics.drawable.LayerDrawable$ChildDrawable.<init>(LayerDrawable.java:1855)
                 at android.graphics.drawable.LayerDrawable$LayerState.<init>(LayerDrawable.java:1975)
                 at android.graphics.drawable.LayerDrawable.createConstantState(LayerDrawable.java:168)
                 at android.graphics.drawable.LayerDrawable.mutate(LayerDrawable.java:1779)
                 at android.graphics.drawable.LayerDrawable.mutate(LayerDrawable.java:1785)
                 at android.graphics.drawable.RippleDrawable.mutate(RippleDrawable.java:997)
                 at android.view.View.applyBackgroundTint(View.java:21809)
                 at android.view.View.setBackgroundDrawable(View.java:21680)
                 at android.support.design.widget.FloatingActionButton.access$001(FloatingActionButton.java:68)
                 at android.support.design.widget.FloatingActionButton$ShadowDelegateImpl.setBackgroundDrawable(FloatingActionButton.java:824)
                 at android.support.design.widget.FloatingActionButtonLollipop.setBackgroundDrawable(FloatingActionButtonLollipop.java:73)
                 at android.support.design.widget.FloatingActionButton.<init>(FloatingActionButton.java:179)
                 at android.support.design.widget.FloatingActionButton.<init>(FloatingActionButton.java:151)
                 at java.lang.reflect.Constructor.newInstance0(Native Method)
                 at java.lang.reflect.Constructor.newInstance(Constructor.java:334)
                 at android.view.LayoutInflater.createView(LayoutInflater.java:647)
                 at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:790)
                 at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
                 at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
                 at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
                 at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
                 at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
                 at android.view.LayoutInflater.inflate(LayoutInflater.java:374) …
Run Code Online (Sandbox Code Playgroud)

android layerdrawable setcontentview android-databinding

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

如何使 BottomSheetDialog 匹配父级高度(全屏)

这是我使用的布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="@+id/layout"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="top|center_horizontal"
android:background="@color/white"
android:gravity="top|center_horizontal"
android:orientation="vertical">

    <TextView
        android:id="@+id/provisioningTitle"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Phone Number" />

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

这是我创建对话框的类:

open class DialogProvisioningData : BottomSheetDialog {
constructor(context: Context) : super(context)


private lateinit var mBehavior: BottomSheetBehavior<FrameLayout>

override fun setContentView(view: View) {
    super.setContentView(view)
    val bottomSheet = window.decorView.findViewById<View>(R.id.design_bottom_sheet) as FrameLayout
    mBehavior = BottomSheetBehavior.from(bottomSheet)
    mBehavior.peekHeight = Resources.getSystem().getDisplayMetrics().heightPixels
    mBehavior.state = BottomSheetBehavior.STATE_EXPANDED
}

override fun onStart() {
    super.onStart()
    mBehavior.peekHeight = Resources.getSystem().getDisplayMetrics().heightPixels
    mBehavior.state = BottomSheetBehavior.STATE_EXPANDED
}

companion object {
    fun newInstance(context: Context): DialogProvisioningData {
        val …
Run Code Online (Sandbox Code Playgroud)

android dialog android-dialog setcontentview bottom-sheet

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

如何使用setcontent使用按钮更改内容视图

我已经看过很多关于如何更改Android屏幕的教程,但我无法理解/完成工作所有这些都可以帮助我完成我的项目.我有四个xml文件,所有这些文件都有三个按钮,但只有两个用于设置页面.我可以让应用程序加载任何一个其他页面(但然后无法建立按钮)(重要的一点).任何帮助表示赞赏.

package com.store.shrek2;


import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends ActionBarActivity {
int activityloaded = 1;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);
    Button button1 = (Button) this.findViewById(R.id.button1);
    Button button2 = (Button) this.findViewById(R.id.button2);
    Button button3 = (Button) this.findViewById(R.id.button3);
    Button button4 = (Button) this.findViewById(R.id.button4);
    Button button5 = (Button) this.findViewById(R.id.button5);
    Button button6 = (Button) this.findViewById(R.id.button6);
    if(activityloaded == 1){
    button1.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
        }});
    button2.setOnClickListener(new …
Run Code Online (Sandbox Code Playgroud)

android view android-activity setcontentview

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

如何阻止UIScrollView到达底部时滚动

我有以下代码来获取UIScrollView到达其内容视图结束时的事件:

- (void) scrollViewDidEndDecelerating:(UIScrollView *) scrollView
{
    float currentEndPoint = scrollView.contentOffset.y + scrollView.frame.size.height;

    // CGPoint bottomOffset = CGPointMake(0, scrollView.contentSize.height - scrollView.bounds.size.height);
    // [scrollView setContentOffset:bottomOffset animated:NO];

    if (currentEndPoint >= scrollView.contentSize.height)
    {
        // We are at the bottom
Run Code Online (Sandbox Code Playgroud)

我注意到当我滚动到底部时它会撞到它并反弹回来.

如果我添加这个:

CGPoint bottomOffset = CGPointMake(0, scrollView.contentSize.height - scrollView.bounds.size.height);
[scrollView setContentOffset:bottomOffset animated:NO];
Run Code Online (Sandbox Code Playgroud)

然后滚动回到底部.

是否有任何方法让它保持在底部没有"反弹",因为一旦它击中底部,阻止它移动.

谢谢.

objective-c uiscrollview ios setcontentview ios8

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

Android:如何从活动类传递多个值到setContentView()方法?

我有一些问题从MainActivityClass传递和显示值到另一个MyActivityClass.所以我在这里学到了如何将值从一个类传递到另一个类.这是MainActivity类的方法,其中包含对其他活动的意图:

Intent intent = new Intent(this, AddAptActivity.class);
Bundle extras = new Bundle();

EditText editText = (EditText) findViewById(R.id.edit_address);
String message = editText.getText().toString();
EditText editText2 = (EditText) findViewById(R.id.edit_name);
String message2 = editText2.getText().toString();

extras.putString(EXTRA_MESSAGE, message);
extras.putString(EXTRA_MESSAGE1, message2);

intent.putExtras(extras);
startActivity(intent);
Run Code Online (Sandbox Code Playgroud)

然后在MyActivityClass中接收值:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Intent intent = getIntent();

    Bundle extras = intent.getExtras();

    String message = extras.getString(MainActivity.EXTRA_MESSAGE);
    String message2 = extras.getString(MainActivity.EXTRA_MESSAGE2);

    TextView textView = new TextView(this);
    textView.setTextSize(40);
    textView.setText(message);

    TextView textView2 = new TextView(this);
    textView2.setTextSize(40);
    textView2.setText(message2);

    setContentView(textView, textView2); 
}
Run Code Online (Sandbox Code Playgroud)

但是setContentView()方法不希望接受多个值.如何在另一个textview中显示其他值然后显示它?

我想我不明白如何使用setContentView显示值...请帮助我,因为我是Android编程的新手(刚刚完成了一周前的第一个教程).

java android setcontentview

0
推荐指数
1
解决办法
3857
查看次数

如何在片段中设置setContentView

我试图在一个片段中调用一个库,但是不知道如何在一个片段中设置它我已经在主要活动中完成了但是我在我的片段中设置setContentView时遇到错误编译依赖

compile 'com.github.medyo:android-about-page:1.0.2'
Run Code Online (Sandbox Code Playgroud)

我的片段内容视图

  @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View rootView  = inflater.inflate(R.layout.fragment_navigation, container, false);
    Element versionElement = new Element();
    versionElement.setTitle("Version 6.2");

    Element adsElement = new Element();
    adsElement.setTitle("Advertise with us");

    View aboutPage = new AboutPage(getActivity())
            .isRTL(false)
            .addItem(versionElement)
            .addItem(adsElement)
            .addGroup("Connect with us")
            .addEmail("elmehdi.sakout@gmail.com")
            .addFacebook("the.medy")
            .addTwitter("medyo80")
            .addYoutube("UCdPQtdWIsg7_pi4mrRu46vA")
            .addPlayStore("com.ideashower.readitlater.pro")
            .addInstagram("medyo80")
            .addGitHub("medyo")
            .create();

    setContentView(aboutPage);
    return rootView;
}
Run Code Online (Sandbox Code Playgroud)

我在倒数第二行得到错误如何解决这个问题.以下库可在api 20+库https://github.com/medyo/android-about-page中使用

android android-fragments setcontentview

0
推荐指数
1
解决办法
6343
查看次数