小编All*_*der的帖子

实现自api 17以来已弃用的滑动抽屉的替代方法

在我的应用程序中,我有一个带有图像按钮的滑动抽屉,点击它时会显示图像描述和信息.所以基本上我只使用一个XML文件和一个Java文件.(但我注意到添加更多图像按钮和图像来显示它需要一段时间才能加载).现在,由于API 17正在弃用滑动抽屉让我有点担心未来的应用程序下载.现在我的问题是,有没有另一种方法可以实现这一点,而无需使用滑动抽屉或旋转器.我真的不想为每个图像创建一个xml和java文件(我最终会得到100+ xml和java)这是我目前的代码.

XML:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">

<ScrollView 
   android:layout_width="wrap_content"
   android:layout_height="wrap_content">
   <RelativeLayout 
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"> 

<ImageView 
    android:id="@+id/iM1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:scaleType="fitStart"
    android:adjustViewBounds="true"/>

</RelativeLayout>
</ScrollView>

<SlidingDrawer
    android:id="@+id/sD1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:content="@+id/content"
    android:handle="@+id/handle">

    <Button
        android:id="@+id/handle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/icon_1" />

    <RelativeLayout
        android:id="@+id/content"
        android:layout_width="match_parent"
        android:layout_height="match_parent" 
        android:background="@drawable/icon_background1">

        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent" >

            <RelativeLayout
                android:layout_width="fill_parent"
                android:layout_height="fill_parent" >

                <Button
                    android:id="@+id/asample"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:background="@drawable/imageicon1"/>
                   .....
Run Code Online (Sandbox Code Playgroud)

和Java:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE); 
    this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN); 
    setContentView(R.layout.campsites);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    final SlidingDrawer slider = (SlidingDrawer) findViewById(R.id.sD1);
    final ImageView imageView = (ImageView) findViewById(R.id.iM1); …
Run Code Online (Sandbox Code Playgroud)

android android-intent android-layout

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

如何解决错误:getSharedPreferences(String,int)未定义类型new View.OnClickListener(){}

我在编码中遇到此错误,并不完全确定如何解决此问题.我已经搜索过尝试解决这个问题,但似乎找不到任何有用的东西.我以前做过这个,但从来没有片段,所以也许是因为那个?

我正在追随exception:

方法getSharedPreferences(String,int)未定义类型new View.OnClickListener(){}

这是我的代码:

public class TestingFragment extends Fragment {

public TestingFragment(){}
private CheckBox ch;
private Context pref;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {

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

    ch = (CheckBox) rootView.findViewById(R.id.checkBox62);
    ch.setOnClickListener(new View.OnClickListener() {
        private String PREFRENCES_NAME;

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
        if(ch.isChecked())
                {
            SharedPreferences pref = getSharedPreferences(PREFRENCES_NAME,0);
            ch.setChecked(pref.getBoolean("cbx62_ischecked" ,true));
            pref.edit().putBoolean("check",false).commit();
            }
        {
        }}
    });
    return rootView;
} }
Run Code Online (Sandbox Code Playgroud)

有人可以帮我这个吗?任何帮助将不胜感激!

android sharedpreferences android-fragments

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

如何实现具有制表符活动的按钮

我有一个标签活动,然后在其中一个活动中,我想放置一个按钮来进行不同的活动.但是,当我编码按钮(没有错误)但启动应用程序时,它崩溃与错误代码:

11-14 12:50:43.783: E/AndroidRuntime(10933): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.dist.distguide/com.dist.distguide.MainActivity}: java.lang.NullPointerException

但是当我删除按钮编码时,应用程序启动正常.

这是我的XML文件:

<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/logo1">

<LinearLayout
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="5dp">

    <TabWidget
        android:id="@android:id/tabs"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />

    <FrameLayout
        android:id="@android:id/tabcontent"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:padding="5dp" >

        <Button
            android:id="@+id/Distancecalc"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Distance Calculator" />

        <Button
            android:id="@+id/Distance"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Distance Calculator" />

    </FrameLayout>

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

然后是我的Java:

Intent intentHome = new Intent().setClass(this, HomeActivity.class);
    TabSpec tabSpecHome = tabHost
        .newTabSpec("Home")
        .setIndicator("", ressources.getDrawable(R.drawable.icon_home_config))
        .setContent(intentHome);
    Button add = (Button)findViewById(R.id.Distance1);
    add.bringToFront(); 
    add.setOnClickListener(new View.OnClickListener()
    {
    public void …
Run Code Online (Sandbox Code Playgroud)

android android-intent

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