小编Bat*_*ati的帖子

如何在Android中获取文件扩展名?

我是新手.我有一个EditText和一个浏览按钮来探索文件夹和仅选择文件.在"浏览"按钮中,单击文件时,它会将该文件所在的文件夹路径存储在一个字符串中,而将其他字符串中没有扩展名的文件名存储在EditText中,我将用于存储这两个字符串中的任何一个.

我想用精确的文件扩展名(无论是一个还是两个点)制作文件名,但我也不知道如何获得文件扩展名.

所有答案将不胜感激. FileChooser.java

    package com.threefriends.filecrypto;

/**
 * Created by hp on 01-06-2016.
 */

import java.io.File;
import java.sql.Date;
import java.util.ArrayList; 
import java.util.Collections;
import java.util.List;
import java.text.DateFormat;
import android.os.Bundle;
import android.app.ListActivity;
import android.content.Intent; 
import android.view.View;
import android.widget.ListView; 

public class FileChooser extends ListActivity {

    private File currentDir;
    private FileArrayAdapter adapter;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState); 
        currentDir=new File("/sdcard/");
        fill(currentDir); 
    }
    private void fill(File f)
    {
        File[]dirs=f.listFiles();
        this.setTitle("Current Dir: "+f.getName());
        List<Item>dir=new ArrayList<Item>();
        List<Item>fls=new ArrayList<Item>();
        try{
             for(File ff: dirs)
             { 
                Date lastModDate=new Date(ff.lastModified()); …
Run Code Online (Sandbox Code Playgroud)

file-extension android

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

如何使用单选按钮组 ID 在 Android 中在不同片段之间进行切换

我是新手。

使用导航栏,应用程序中的片段。

文件说明:

fragment_settings.xml:包含单选按钮组

SettingsFragment.java:主要是在导航抽屉中单击设置时显示 fragment_settings.xml。我检查了不同的

MainFragment.java:这里,我想使用RadioButton id,点击进入开关盒,然后执行相应的操作。

但问题是控制权进入了交换机,但不是在案例中,我尝试过放入吐司,但 id 与任何案例都不匹配。

fragment_settings.xml

    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    tools:context="com.threefriends.filecrypto.SettingsFragment">

    <!-- TODO: Update blank fragment layout -->
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">

        <TextView
            android:id="@+id/textview2"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Choose algorithm:"
            android:textSize="18dp"
            android:layout_marginLeft="10dp"
            android:layout_marginTop="71dp"
        />
        <RadioGroup
            android:id="@+id/radioAlgorithms"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">

            <RadioButton
                android:id="@+id/radioaes"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="AES (Default)"
                android:checked="true"
                android:layout_marginLeft="5dp"
            />
            <RadioButton
                android:id="@+id/radiodes"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="DES"
                android:layout_marginLeft="5dp"
                />
            <RadioButton
                android:id="@+id/radioidea"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="IDEA"
                android:layout_marginLeft="5dp"
            />
            <RadioButton
                android:id="@+id/radiocustom"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Custom"
                android:layout_marginLeft="5dp"
                />
        </RadioGroup> …
Run Code Online (Sandbox Code Playgroud)

java android android-fragments

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

标签 统计

android ×2

android-fragments ×1

file-extension ×1

java ×1