小编use*_*305的帖子

如何使用存储在非活动类的sharedpreferences中的数据

我试图从非活动类中获取并更新我存储在sharedpreferences xml文件中的数据.但我不知道如何从android中的非活动类到达存储在sharedPreferences中的数据.在我的活动类中,我可以将数据存储在sharedprefences中,我也可以在我的活动类中检索这些数据.但是,我无法从非活动类中检索这些数据.我的代码如下.谢谢你......

    mSharedPrefs = getSharedPreferences("storageforfavorite", 0);
    mPrefsEditor = mSharedPrefs.edit();

    for(int i= 0;i<names.size();i++){
        mPrefsEditor.putString(indexForFav[i],"0"); 
    }
    mPrefsEditor.commit();

    for(int i=0;i<names.size();i++){
        String keyForFav=mSharedPrefs.getString(indexForFav[i], "2");
        valueForFav.add(keyForFav);
    }
Run Code Online (Sandbox Code Playgroud)

android sharedpreferences

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

动态设置ID到Android中的按钮

我想动态创建一个按钮,但在为它设置ID时遇到了问题.我尝试在那里放一个整数值,但一直收到错误,说明"Expected Resource of Type ID."问题是我不想在我的XML文件中创建这个Button但我需要一种方法来跟踪它的ID.请帮忙.

Button changeButton = new Button(getApplicationContext());
changeButton.setText("Change");
changeButton.setId(1);//Keep Getting an error here
Run Code Online (Sandbox Code Playgroud)

android android-resources

3
推荐指数
2
解决办法
8054
查看次数

如何从android中的每个listview项调用不同的意图?

我正在研究android应用程序.在我的项目中,我需要创建Listview.我的布局即info.xml包含带有一个图像视图的topbar,带有其他imageview的页脚.同样在布局的中心,我保留了一个imageview,并且我创建了Listview.我还为textview创建了row.xml来显示listitems.现在当我点击每个listitem时,应该调用一个新的意图...即当我点击1st listitem page1时应该打开.同样,如果我点击第二个listitem页面2应该打开,依此类推.那我怎么能这样做呢.我3天来一直在努力,但没有找到任何正确的解决方案.请关注此事.

我的代码:

public class Information extends Activity 
{
private String[] Countries;

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.information);
Countries = getResources().getStringArray(R.array.countries);
ListView list = (ListView)findViewById(R.id.listnew);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.row, Countries);
list.setAdapter(adapter);
registerForContextMenu(list);  }
} 
Run Code Online (Sandbox Code Playgroud)

android

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

Android两个edittext应该显示在键盘上方

这个问题可能看起来很简单,但我不知道答案.在登录页面中,我有两个edittext,当第一个edittext聚焦时,键盘出现并隐藏第二个edittext,这对我来说是个问题.我需要的是,当键盘出现时,它不应该隐藏第二个edittext,而应该显示它们.等待有价值的评论和回应.

编辑:#1

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" android:layout_height="fill_parent">
    <RelativeLayout android:orientation="vertical"
    android:layout_width="fill_parent" android:layout_height="fill_parent"
    android:background="@drawable/login_bg">
    <!-- <ScrollView android:layout_width="fill_parent" android:layout_height="fill_parent" 
        android:id="@+id/loginScrollView" android:layout_above="@+id/footer" android:scrollbars="vertical" 
        android:fadingEdge="none"> -->
    <LinearLayout android:orientation="vertical"
        android:layout_width="fill_parent" android:layout_height="fill_parent"
        android:id="@+id/loginMainLayout" android:layout_above="@+id/footer">

        <ImageView android:layout_width="fill_parent" android:id="@+id/logo_image_login"
            android:layout_height="0dip" android:layout_weight="27"
            android:src="@drawable/video_date_logo_a" android:scaleType="fitCenter"
            android:layout_marginTop="20dip" android:layout_marginBottom="0dip"></ImageView>

        <TableLayout android:layout_width="fill_parent"
            android:layout_height="0dip" android:layout_weight="23"
            android:paddingLeft="5dip" android:paddingRight="5dip">
            <TableRow android:layout_marginLeft="10dip"
                android:layout_height="0dip" android:layout_weight="1"
                android:layout_marginRight="5dip" android:layout_marginTop="10dip"
                android:layout_marginBottom="5dip" android:gravity="center_vertical">
                <TextView android:layout_width="0dip"
                    style="@style/ivideodate.blue.small" android:layout_weight="0.35"
                    android:layout_height="wrap_content" android:text="@string/login_email"></TextView>
                <EditText android:layout_width="0dip" android:id="@+id/login_emailid"
                    android:layout_weight="0.80" android:layout_height="wrap_content"
                    android:maxLength="40" android:singleLine="true" android:text=""
                    style="@style/ivideodate.black.input" android:background="@drawable/tagline_bg_a"
                    android:focusableInTouchMode="true" android:layout_marginRight="5dip"
                    android:inputType="textEmailAddress"></EditText>
            </TableRow>
            <TableRow android:layout_marginLeft="10dip"
                android:layout_marginRight="5dip" android:layout_marginTop="10dip"
                android:layout_marginBottom="5dip" android:layout_height="0dip"
                android:layout_weight="1" android:gravity="center_vertical"> …
Run Code Online (Sandbox Code Playgroud)

keyboard android android-edittext

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

获取视图无法解析为函数类型错误

我是Android/java编程的新手.我真的不知道我在做什么,并希望得到一些帮助.我想要做的是建立一个非常类似于下面的形式.我已经放入了所有布局和字符串信息,但是我遇到了这些功能问题.我得到的错误是View无法解析为类型行14.我使用eclipse来帮助我编写这个应用程序.这是我的main.xml,以及MadisonStudios.java文件的内容. http://mobile.tutsplus.com/tutorials/android/android-sdk-creating-forms/

main.xml中

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/welcome" />

    <EditText
        android:id="@+id/EditTextName"
        android:layout_height="wrap_content"
        android:hint="@string/name"
        android:inputType="textPersonName"
        android:layout_width="fill_parent">
    </EditText>

    <EditText
        android:id="@+id/EditTextEmail"
        android:layout_height="wrap_content"
        android:hint="@string/email"
        android:inputType="textEmailAddress"
        android:layout_width="fill_parent">
    </EditText>

    <Spinner
        android:id="@+id/SpinnerStatus"
        android:layout_height="wrap_content"
        android:prompt="@string/status"
        android:layout_width="fill_parent"
        android:entries="@array/statuslist">
    </Spinner>

    <EditText  
        android:id="@+id/EditTextFeedbackBody"  
        android:layout_height="wrap_content"  
        android:hint="@string/changebody"  
        android:inputType="textMultiLine"  
        android:lines="5"  
        android:layout_width="fill_parent">  
    </EditText>

    <Button
        android:id="@+id/ButtonSendChange"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:onClick="sendChange"
        android:text="@string/changebutton">
    </Button>

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

MadisonStudios.java

package com.madisonstudios.supportapp;

import android.app.Activity; 
import android.os.Bundle;

 public class MadisonStudios extends Activity {
     /** Called when the activity is first created. */
     @Override
     public void onCreate(Bundle …
Run Code Online (Sandbox Code Playgroud)

android function

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