小编Bug*_*pen的帖子

当我们滚动列表时,自定义列表视图中的Android单选按钮会更改其状态

我是一个初学者,面临一个问题,我正在创建一个ListView有两个RadioButton和一个TextView.一切都很顺利,但是当我设置RadioButton并滚动它时,先前RadioButton的值会改变它们的值或者显着地失去它们的状态.我试图解决这个问题很长一段时间.我应该做些什么改变来克服这个问题?

MainActivity.java

public class MainActivity extends Activity {

     private ListView listView1;
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);

            Option weather_data[] = new Option[]
                    {
                        new Option("Heading1"),
                        new Option("Heading12"),
                        new Option("Heading3"),
                        new Option("Heading4"),
                        new Option("Heading5"),
                        new Option("Heading6"),
                        new Option("Heading7"),
                        new Option("Heading8"),
                        new Option("Heading9"),
                        new Option("Heading10")
                    };
            RadioGroupAdapter adapter = new RadioGroupAdapter(this, 
                            R.layout.listitem, weather_data);
                    listView1 = (ListView)findViewById(R.id.list);
                    listView1.setAdapter(adapter);
        }

        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            getMenuInflater().inflate(R.menu.activity_main, menu);
            return true;
        }
    } …
Run Code Online (Sandbox Code Playgroud)

android listview radiobuttonlist adapter radio-button

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

添加Google Analytics后无法生成APK,但在调试模式下正常运行

这是一个非常奇怪的情况.我可以构建我的项目,清理和构建我的项目,甚至可以在具有调试模式的物理设备上运行.我还获得了Google Analytics网页上所需的所有数据.

可悲的是,Android Studio没有生成发行版,.apk文件.我完全按照向您的Android应用程序添加分析,官方教程,并搜索了许多答案,但确切的问题仍然存在.

我的build.gradle看起来像这样:

apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.0"

    defaultConfig {
        applicationId "com.comname.appname"
        minSdkVersion 11
        targetSdkVersion 23
        versionCode 18
        versionName "2.7"
    }
    buildTypes {
        release {
            minifyEnabled true
            zipAlignEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}


dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile files('libs/achartengine-1.1.0.jar')
    compile files('libs/SalatCalculator.jar')
    compile 'com.android.support:appcompat-v7:23.0.0'
    compile 'com.android.support:support-v4:23.0.0'
    compile 'com.google.android.gms:play-services-analytics:7.8.0'
}
Run Code Online (Sandbox Code Playgroud)

这是Gradle Build报告:

Information:Gradle tasks [:app:assembleRelease]
:app:preBuild UP-TO-DATE
:app:preReleaseBuild UP-TO-DATE
:app:checkReleaseManifest
:app:preDebugBuild UP-TO-DATE
:app:prepareComAndroidSupportAppcompatV72300Library UP-TO-DATE …
Run Code Online (Sandbox Code Playgroud)

android google-analytics android-studio

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

ITextPdf:从右到左打印阿拉伯字符串 (RTL)

我在 java 上使用 iTextpdf 来生成加盖的 PDF,有时生成的 PDF 是阿拉伯语,我面临一个有趣的问题。为了让阿拉伯语页面从右到左 (RTL) 创建,我使用具有属性的表格和单元格PdfPCell.setRunDirection(PdfWriter.RUN_DIRECTION_RTL)。当我使用此属性时,阿拉伯语根本不显示,如果我避免调用此属性时正确显示阿拉伯语字符串,这意味着我不应该遇到字体问题,而且我真的不知道这是否是 iText 的问题或者我只是错过了一些东西。

这里有一小段代码正确显示了一个阿拉伯字符串:

BaseFont bf = BaseFont.createFont(Application.getBASEPATH() + "fonts/arabic.ttf",BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
Font trebuchetSmaller = new Font(bf, 10, 0);

PdfPTable tbl = new PdfPTable(1); 
PdfPCell cell = new PdfPCell();
Paragraph paragraph = new Paragraph();
paragraph.add(new Phrase("??? ???? ??? ???? ????????"), trebuchetSmaller));
cell.addElement(paragraph);
tbl.addCell(cell);
Run Code Online (Sandbox Code Playgroud)

这里使阿拉伯字符串消失所需的更改:

BaseFont bf = BaseFont.createFont(Application.getBASEPATH() + "fonts/arabic.ttf",BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
Font trebuchetSmaller = new Font(bf, 10, 0);

PdfPTable tbl = new PdfPTable(1); 
PdfPCell cell = new PdfPCell();
cell.setRunDirection(PdfWriter.RUN_DIRECTION_RTL);
Paragraph …
Run Code Online (Sandbox Code Playgroud)

java pdf-generation arabic itext right-to-left

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

提示在非焦点状态下使用TextInputLayout不可见

我正在使用TextInputLayoutAndroid设计库中的新功能,

EditText集中,一切都还好,我可以看到上面的提示EditText

在此处输入图片说明

但是当EditText失去焦点时,提示完全消失了:

在此处输入图片说明

我希望提示会返回到EditText,我还缺少什么?

下面的xml代码。

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:padding="20dp">

    <android.support.design.widget.TextInputLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="Try me!"/>
    </android.support.design.widget.TextInputLayout>

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:hint="Try me 2"/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

android hint android-design-library android-textinputlayout

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

设置ConstraintLayout宽度以编程方式匹配父宽度

在Android应用程序中,我试图以编程方式将自定义ConstraintLayout视图添加到垂直方向LinearLayout.

我设置LayoutParamsMATCH_PARENT宽度和WRAP_CONTENT在身高ConstraintLayout秒.但是,当我运行应用程序时,ConstraintView所有应用程序都被刷新,内容重叠.以下是一些相关的片段和我的应用程序的屏幕截图.我该如何纠正这个问题?

public class ItemView extends ConstraintLayout {
    LinearLayout linearButtons;
    LinearLayout linearText;
public ItemView(Context context, String name, String price, ArrayList<String> guests, 
   ArrayList<String> checked, int id) {
...
    addView(linearText);
    addView(linearButtons);
    set.clone(this);
    set.connect(linearText.getId(), ConstraintSet.LEFT, this.getId(), 
      ConstraintSet.LEFT, 8);
    set.connect(linearText.getId(), ConstraintSet.TOP, this.getId(), 
     ConstraintSet.TOP, 8);
    set.connect(linearButtons.getId(), ConstraintSet.RIGHT, this.getId(), 
     ConstraintSet.RIGHT, 8);
    set.connect(linearButtons.getId(), ConstraintSet.TOP, this.getId(), 
     ConstraintSet.TOP, 8);
}
Run Code Online (Sandbox Code Playgroud)

别处:

for (Item it:r.getItems()) {
        ItemView itemView = new ItemView(this, it.getName(), nf.format(it.getPrice()), dinerlist, it.getGuests(), i); …
Run Code Online (Sandbox Code Playgroud)

android android-layout android-constraintlayout

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

垂直滚动Android中的RecyclerView按像素

在我的聊天应用程序中,我使用RecyclerView和LayoutManager来显示聊天消息列表.我有一个用户浏览旧邮件和新邮件到达的情况.此时我想以小距离滚动聊天以确认收到新消息的用户.我需要以像素为单位滚动我的RecyclerView.我发现layoutManager有方法scrollVerticallyBy,

public int scrollVerticallyBy (int dy, RecyclerView.Recycler recycler, RecyclerView.State state)
Run Code Online (Sandbox Code Playgroud)

但我对它所需的参数,RecyclerView.Recycler recycleler,RecyclerView.State状态感到困惑,我不确定它是否能完成我的工作.

换句话说,我想找到ListView.smoothScrollBy的重复版(int distance,int duration);

android android-recyclerview

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

登录Twitter失败

当我在我的Android应用程序中使用twitter登录时,我遇到了一些问题.错误日志如下:

09-05 15:38:48.492 22119-22119/sg.com.conversant.swiftlive E/Twitter: Failed to get request token com.twitter.sdk.android.core.TwitterApiException: HTTP request failed, Status: 401
   at com.twitter.sdk.android.core.Callback.onResponse(Callback.java:42)
   at retrofit2.ExecutorCallAdapterFactory$ExecutorCallbackCall$1$1.run(ExecutorCallAdapterFactory.java:68)
   at android.os.Handler.handleCallback(Handler.java:733)
   at android.os.Handler.dispatchMessage(Handler.java:95)
   at android.os.Looper.loop(Looper.java:136)
   at android.app.ActivityThread.main(ActivityThread.java:5118)
   at java.lang.reflect.Method.invokeNative(Native Method)
   at java.lang.reflect.Method.invoke(Method.java:515)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:794)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:610)
   at dalvik.system.NativeStart.main(Native Method)
09-05 15:38:48.552 22119-22119/sg.com.conversant.swiftlive E/Twitter: Authorization completed with an error com.twitter.sdk.android.core.TwitterAuthException: Failed to get request token
   at com.twitter.sdk.android.core.identity.OAuthController$1.failure(OAuthController.java:95)
   at com.twitter.sdk.android.core.internal.oauth.OAuth1aService$1.failure(OAuth1aService.java:194)
   at com.twitter.sdk.android.core.Callback.onResponse(Callback.java:42)
   at retrofit2.ExecutorCallAdapterFactory$ExecutorCallbackCall$1$1.run(ExecutorCallAdapterFactory.java:68)
   at android.os.Handler.handleCallback(Handler.java:733)
   at android.os.Handler.dispatchMessage(Handler.java:95)
   at android.os.Looper.loop(Looper.java:136)
   at android.app.ActivityThread.main(ActivityThread.java:5118)
   at java.lang.reflect.Method.invokeNative(Native Method)
   at java.lang.reflect.Method.invoke(Method.java:515)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:794)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:610) …
Run Code Online (Sandbox Code Playgroud)

twitter android

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

SQLite外键无法正常工作

以下是创建表的查询:

CREATE TABLE "FacilityRating"(
    "FacilityRatingId" INTEGER PRIMARY KEY NOT NULL,
    "Stars" VARCHAR,
    "Facility_FacilityId" INTEGER,
    "User_UserId" INTEGER,
    FOREIGN KEY (Facility_FacilityId)
        REFERENCES Facility(FacilityId)
        ON DELETE CASCADE
        ON UPDATE CASCADE,
    FOREIGN KEY (User_UserId)
        REFERENCES User(UserId)
        ON DELETE CASCADE
        ON UPDATE CASCADE
)
Run Code Online (Sandbox Code Playgroud)

然而,当我在插入新行Facility_FacilityIdUser_UserId一些随机数,SQLite不给错误,但增加了也无妨.

这是一个快照:

在此输入图像描述

有什么暗示这里发生了什么?我正在使用SQLite Manager,一个Mozilla Firefox附加组件

sqlite foreign-keys sqlitemanager

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

如何将 C# 字符串转换为 Java.Lang.String?

我正在与 Xamarin 合作。这就是问题所在。其中一个函数Java.Lang.String作为其参数接收,而我有StringC#。我需要将 C# 的字符串类型转换为 Java 的字符串。

我怎样才能做到这一点?有什么建议?

谢谢。

java string type-conversion xamarin.android xamarin

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

在ViewPager android中显示两个项目

我正在从这个网站开发示例教程。

在本教程中,每个 只显示一个项目ViewPager,但我想显示两个项目。在我进行了一些定制后,它在一个寻呼机中显示了两个项目。但两种观点是一样的。我不要。我想在屏幕上显示不同的视图。

谢谢。

测试活动.java

public class TestingActivity extends ActionBarActivity {
    // Declare Variables
    ViewPager viewPager;
    PagerAdapter adapter;
    String[] rank;
    String[] country;
    String[] population;
    int[] flag;
    CirclePageIndicator mIndicator;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // Get the view from viewpager_main.xml
        setContentView(R.layout.viewpager_main);

        // Locate the ViewPager in viewpager_main.xml
        viewPager = (ViewPager) findViewById(R.id.pager);
        // Pass results to ViewPagerAdapter Class
        adapter = new ViewPagerAdapter(TestingActivity.this, rank, country,
                population, flag);
        // Binds the Adapter to the ViewPager
        viewPager.setAdapter(adapter);

        // ViewPager …
Run Code Online (Sandbox Code Playgroud)

android android-viewpager

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

在C#Dictionary中交换两个键/值对

这就是我想要做的.

有一个包含54个键/值对象的Dictionary.我希望索引i处的键/值对与索引j处的键/值对交换...

int i=1; int j=3;
Dictionary<String, int> theDeck = new Dictionary<String, int>();
theDeck.Add("zero",  0);
theDeck.Add("one",   1);
theDeck.Add("two",   2);
theDeck.Add("three", 3);
KeyValuePair<String, int> p1 = theDeck.ElementAt(i);
KeyValuePair<String, int> p2 = theDeck.ElementAt(j);
theDeck.ElementAt(i) = p2; //THIS LINE DOES NOT WORK. WHAT IS ITS ALTERNATIVE
theDeck.ElementAt(j) = p1; //THIS LINE DOES NOT WORK. WHAT IS ITS ALTERNATIVE
Run Code Online (Sandbox Code Playgroud)

c# swap dictionary key-value

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

无法从记住块调用@Composable函数

我想在函数中计算 Box 的高度,并且希望 compose 记住其结果而不是再次调用该函数。该函数具有一些可组合的内容,因此它是一个@Composable函数。

问题是,Compose 不允许我从remember块调用这个函数。

这是我的代码:

val coverImageHeightInDp = remember {
    viewModel.calculateTopCoverHeightInDp()
}

Box(modifier = Modifier
    .then(modifier)
    .fillMaxWidth()
    .height(coverImageHeightInDp)
)
Run Code Online (Sandbox Code Playgroud)

以及以下函数viewModel

@Composable
fun calculateTopCoverHeightInDp(): Dp {
    val originalImageDimens = Size(1440f, 828f)
    val imageRatio = originalImageDimens.width / originalImageDimens.height
    val configuration = LocalConfiguration.current
    val screenWidthInDp = configuration.screenWidthDp.dp
    return screenWidthInDp / imageRatio
}
Run Code Online (Sandbox Code Playgroud)

我该如何编码才能记住该函数的结果并且在屏幕旋转之前不会再次调用该函数?

谢谢。

android composition android-jetpack android-jetpack-compose

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