小编Lal*_*Lal的帖子

删除字符串数组中具有相同字符的字符串

我现在正面临一个问题.在我的一个程序中,我需要从Array中删除具有相同字符的字符串.例如.假设,

我有3个阵列,

String[] name1 = {"amy", "jose", "jeremy", "alice", "patrick"};
String[] name2 = {"alan", "may", "jeremy", "helen", "alexi"};
String[] name3 = {"adel", "aron", "amy", "james", "yam"};
Run Code Online (Sandbox Code Playgroud)

正如你所看到的,有一个字符串amy中的name1数组.此外,我有类似的字符串may,amyyam在接下来的两个数组中.我需要的是,我需要一个不包含这些重复字符串的最终数组.我只需要出现一次:我需要删除最终数组中名称的所有排列.那是最后一个数组应该是:

String[] finalArray={"amy", "jose", "alice", "patrick","alan", "jeremy", "helen", "alexi","adel", "aron", "james"}
Run Code Online (Sandbox Code Playgroud)

(上面的数组删除了山药,可能,只包括amy).

我到目前为止尝试使用的HashSet,如下所示

String[] name1 = {"Amy", "Jose", "Jeremy", "Alice", "Patrick"};
String[] name2 = {"Alan", "mAy", "Jeremy", "Helen", "Alexi"};
String[] name3 = {"Adel", "Aaron", "Amy", "James", "Alice"};
Set<String> letter = new HashSet<String>(); …
Run Code Online (Sandbox Code Playgroud)

java arrays string duplicate-removal

18
推荐指数
2
解决办法
1527
查看次数

ACCESS_FINE_LOCATION权限

我很惭愧.但是找不到什么是错的.

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.szymon.gpslab1"
android:versionCode="15"
android:versionName="4.0.3">

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.INTERNET"/>

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:theme="@style/AppTheme.NoActionBar" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>
</manifest>
Run Code Online (Sandbox Code Playgroud)

这是我的表现.这是我的代码:

public class MainActivity extends AppCompatActivity {
LocationManager locationManager;
LocationListener locationListener;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    locationListener = new MyLocationListener();

    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);
}
private class MyLocationListener implements LocationListener{

    @Override
    public …
Run Code Online (Sandbox Code Playgroud)

gps android android-permissions

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

如何以固定速率记录Android Motion Sensors的数据

我正在学习Android编程的基础知识.

我有一个简单的android测试应用程序,其中我将加速度计,磁力计和方向数据记录到外部文件,同时也显示它.我通过调用方法initLogger来单击Start按钮(相关传感器的registerListener)来启动日志记录过程.

看起来与此类似......

public void initLogger(View view)
{
    boolean bFlag = false;

    Button btnStart = (Button)findViewById(R.id.btnStartLog);
    Button btnStop = (Button)findViewById(R.id.btnStopLog);

    btnStart.setEnabled(bFlag);
    btnStop.setEnabled(!bFlag);

    bEnableLogging = true;
    //Start reading the sensor values
    sensorManager.registerListener(this, sensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD), SensorManager.SENSOR_DELAY_UI);
    sensorManager.registerListener(this, sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_UI);

   //so on.... 
Run Code Online (Sandbox Code Playgroud)

还有一个Stop按钮,它将停止记录过程(最后通过为每个传感器调用unregisterListener来取消注册)

数据检索过程发生在onSensorChanged处理程序中,该处理程序将从相关传感器检索数据,将值设置为相应的UI元素,最后将数据记录到外部.csv文件.

onSensorChanged事件处理程序看起来像这样......

public void onSensorChanged(SensorEvent event) {


    // TODO Auto-generated method stub
    // accelerometer
    TextView tAX = (TextView) findViewById(R.id.txtViewAxValue);
    TextView tAY = (TextView) findViewById(R.id.txtViewAyValue);
    TextView tAZ = (TextView) findViewById(R.id.txtViewAzValue);

    // magnetic field
    TextView tMX …
Run Code Online (Sandbox Code Playgroud)

java android android-sensors sensor-fusion

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

如何在android studio中添加卫星视图?

我的地图工作正常.但是,我想添加一个卫星视图和我的普通视图?我怎样才能实现这一目标?

public class MainActivity extends FragmentActivity implements OnMapReadyCallback {


private GoogleMap mMap;

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

    SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
            .findFragmentById(R.id.map);
    mapFragment.getMapAsync(this);
}



@Override
public void onMapReady(GoogleMap googleMap) {
    mMap = googleMap;


    LatLng location = new LatLng(x,y);
    mMap.addMarker(new MarkerOptions().position(ReduitBusStop).title("you are here!"));
    mMap.moveCamera(CameraUpdateFactory.newLatLng(location));
Run Code Online (Sandbox Code Playgroud)

android view satellite

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

如何防止android软键盘调整我的活动大小

我有一个活动,指定为此行的对话框,Manifest如下所示

android:theme="@android:style/Theme.Dialog"

那么如何防止软键盘上推和调整大小?

android dialog android-softkeyboard

7
推荐指数
2
解决办法
5559
查看次数

是否有相当于Android应用程序的http会话?

有没有办法为Android应用程序定义类似"会话"的东西?
我有一个启动多个活动的应用程序和应用程序从活动到活动等的用户
.当然可以切换到另一个应用程序,接听电话,停止使用该应用程序,因为他很忙,所以应用程序在后台等.
是否有一种简单而有意义的方法可以在所有这些不同情况下定义类似单个会话的内容?这样我们可以判断新会话何时开始并可能为每个会话存储一些数据?

android android-activity

7
推荐指数
2
解决办法
547
查看次数

如何使用android studio将子模块推送到github?

我从github克隆了一个android项目.我在克隆后进行了更改,并将其从android studio推送到主存储库.一切都运行正常但是当我在项目中添加外部库时,我无法推动它.我认为它是一个子模块.谁能告诉我如何将外部库作为android工作室的子模块?

android github android-studio

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

Android Studio:每天使用listView创建一个calendarView

我是Android工作室的新手,所以只是判断.

我想创建一个每天都有下面列表的日历.这就是我所拥有的:在此输入图像描述

但是我一直在努力探讨如何为每个函数编写函数.在fragmentManager的帮助下,我在一个视图中有两个想法,比如两个片段.或者只是将SimpleAdapter添加到FragmentA.java以获取列表.

我想说的是,我真的不知道自己想要什么!我会感谢一些指示/指导或示例?

我在Fragments中有我的功能代码.我的活动是在FragmentA.java,B和C之间运行一个滑动功能.

fragment_a.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:clickable="true"
    android:focusable="true">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.5"
        android:clickable="true"
        android:focusable="true">

        <CalendarView
            android:id="@+id/calendarView1"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:adjustViewBounds="true"
            android:clickable="true" />

    </RelativeLayout>
        <ListView
            android:id="@+id/dailyView1"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="0.5"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="5dp"
            android:layout_gravity="center_horizontal|center"
            android:clickable="true"
            android:focusable="true" />

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

很高兴你会这样做.这个日历将在和...说话.

谢谢!

android listview calendar calendarview android-studio

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

在活动结果相机意图在三星s4中返回null


在此先感谢您的帮助.这是我在创建第一个应用程序时遇到的问题.

我正在制作应用程序,其中用户可以选择从图库或相机拍摄图像,当从图库导入图像时,应用程序正在按需工作,但是当从相机拍摄图像时intent返回null.

Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); 
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
startActivityForResult(cameraIntent,YOUR_SELECT_PICTURE_REQUEST_CODE);
Run Code Online (Sandbox Code Playgroud)

camera android android-intent

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

Android EditText背景里面有一行

我正在为我的EditText创建背景,我想在文本下添加一行.

我的背景代码:

<item android:state_pressed="true" android:state_focused="true">
    <shape>
        <solid android:color="#10FFFFFF" />
        <corners android:radius="5dp" />
    </shape>
</item>
Run Code Online (Sandbox Code Playgroud)

如何在形状内添加线条?

从图形项目预览: 在此输入图像描述

android background underline textfield android-edittext

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