小编Gab*_*han的帖子

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

自定义视图由多个视图组成

我有一组想要一直使用的视图.这方面的一个例子可能是这样的:

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

文本视图是一个提示,编辑视图就是答案.我想给这个组合命名,并能够使用该名称将其弹出到xml中.我喜欢它是一个自定义视图,所以我可以很好地把它放在一个类中,并为它创建各种实用程序功能.有什么方法可以做到吗?我知道我可以继承LinearLayout并在java代码中动态创建子项,但这使我无法通过xml轻松进行更改.有更好的路线吗?

是的,我还有一些我想要做的事情,而不仅仅是提示.

android android-layout

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

RecycerView直到滚动后才显示

在滚动之前,我有一个不显示任何元素的回收器视图.一旦我滚动它,任何完全在屏幕外的项目都会显示,但任何未经过的项目都不会显示.

片段类:

public class ImageAndNavHeaderFragment extends Fragment {
    private NetworkImageView mBackgroundImage;
    private RecyclerView mScrollingTextNavBar;
    private ScrollingTextNavBarAdapter mScrollingBarAdapter;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.image_and_nav_header, container, false);
        mBackgroundImage = (NetworkImageView) view.findViewById(R.id.bgImage);
        mBackgroundImage.setImageUrl("http://crookedcreekguides.com/wp-content/uploads/2016/01/dinner-03.jpg", VolleySingleton.getInstance(getContext()).getImageLoader());
        mScrollingTextNavBar = (RecyclerView) view.findViewById(R.id.scrollTextNavBar);


        LinearLayoutManager layoutManager = new LinearLayoutManager(getContext());
        layoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
        mScrollingTextNavBar.setLayoutManager(layoutManager);


        ArrayList<String> list = new ArrayList<>();
        for(int i=0; i< 20; i++) {
            list.add("Test " + i);
        }

        mScrollingBarAdapter = new ScrollingTextNavBarAdapter(getContext(), list);
        mScrollingTextNavBar.setAdapter(mScrollingBarAdapter);
        view.invalidate();
        return view;
    }
}
Run Code Online (Sandbox Code Playgroud)

适配器

public class …
Run Code Online (Sandbox Code Playgroud)

android android-recyclerview

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

newSpellCheckerSession始终返回null

我正试图在我的Note平板电脑上加入内置的Android拼写检查服务.我打电话的时候

    final TextServicesManager tsm = (TextServicesManager) getSystemService(
            Context.TEXT_SERVICES_MANAGER_SERVICE);
    spellCheck = tsm.newSpellCheckerSession(null, null, this, true);        
Run Code Online (Sandbox Code Playgroud)

spellCheck始终为null.设备是4.1.2,所以它应该至少具有建议功能这个词.有没有人直接使用这项服务给我一些指示?网络非常稀疏,因为它通常来自键盘.

android spell-checking

8
推荐指数
1
解决办法
1599
查看次数

您能查询Firebase App Indexing的个人内容吗?

我有一个实施Firebase应用程序索引的应用程序.它还有自己的全文搜索实现.谷歌显然更好,我喜欢杀死我使用的那个,而不是他们的.是否可以根据自己应用的个人内容查询Firebase应用索引?我不需要/想要任何其他应用程序的内容,只有我自己的内容.

android android-app-indexing google-app-indexing firebase-app-indexing

8
推荐指数
1
解决办法
192
查看次数

无法在未调用Looper.prepare()3的线程内创建处理程序

public class AddStudentActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_add_student);
}

public void add2(View view){
    //create 3 editText  ,  1 Textview
    EditText et_name, et_age;
    RadioButton rb_male;
    TextView tv_msg;

    //bind with xml widget
    et_name = (EditText)findViewById(R.id.et_name);
    et_age = (EditText)findViewById(R.id.et_age);
    rb_male = (RadioButton)findViewById(R.id.rb_male);
    tv_msg = (TextView)findViewById(R.id.tv_msg);
    //retrieve values
    String name = et_name.getText().toString();
    String age = et_age.getText().toString();
    String gender = "";
    if (rb_male.isChecked())
        gender = "male";
    else
        gender = "female";
    //call php
    new AddStudent(this, tv_msg).execute(name, age, gender);
   }
} …
Run Code Online (Sandbox Code Playgroud)

android ui-thread toast

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

使用Otto,方法只有在我直接在其他地方调用它时才会订阅

我有一个问题,我的订阅方法之一不会被调用正确的事件类型的帖子,除非在其他地方使用(调用)订阅方法.

以下是有关代码的一些相关信息:

  • 我的一个类的方法用@Subscribe注释.
  • 通过使用调试器逐步执行代码,我发现在我的特定情况下,该类没有使用@Subscribe注释的方法.
  • 除非我在某个时间点直接调用该方法(无论何时,或者甚至在运行时实际调用它),我的帖子都不起作用.
  • IDE(Android Studio)通知我"方法永远不会被使用"

我当然可以在一段代码中调用该方法,我相信它永远不会解雇,但这显然是一种可怕的做法,并且违背了这个帖子/订阅范例的目的.

或者我可以使方法静态,但我宁愿不这样做,因为我在其中使用成员变量.

尽管奥托的例子使用了类似的模式,但为什么会发生这种情况的任何解决方案

java android proguard otto

3
推荐指数
1
解决办法
601
查看次数