小编KeL*_*yue的帖子

clrscr()不工作,getch()工作.为什么?

我正在制作一个小C程序,要求输入密钥并在switch语句中执行一些代码.

#include <stdio.h>
#include <conio.h>

int main(int argc, char const *argv[]){
    /* code */
    printf("Hello, press a, b or c to continue");
    char key = getch();
    switch (key){
    case  'a':
        clrscr();
        //some code
        break;
    case  'b':
        //many lines of code
        break;
    case  'c':
        clrscr();
        //many lines of code
        break;
    default:
        printf("Ok saliendo\n");
        break;
    }
    printf("bye");
}
Run Code Online (Sandbox Code Playgroud)

getch()工作正常,但clrscr()不是,即使我包括在内<conio.h>.

为什么?

c gcc conio

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

DrawerLayout 必须使用 MeasureSpec.EXACTLY 进行测量。在 android.support.v4.widget.DrawerLayout.onMeasure(DrawerLayout.java:994)

这是我的mainlayout文件。

这是主布局文件,我在其中编写与导航抽屉相关的代码,还使用 ​​include 包含工具栏。

    <LinearLayout android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        xmlns:tools="http://schemas.android.com/tools"
        xmlns:android="http://schemas.android.com/apk/res/android">
        <android.support.v4.widget.DrawerLayout
            android:id="@+id/navigation_Drawerlayout"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            tools:openDrawer="start">
            <include layout="@layout/navigation_drawerlayout" />

            <android.support.design.widget.NavigationView
                android:id="@+id/navigation_View"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_gravity="start"
                android:fitsSystemWindows="true">

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical">

                    <include layout="@layout/navigation_headerview" />

                    <android.support.v7.widget.RecyclerView
                        android:id="@+id/navigationRecycleView"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"></android.support.v7.widget.RecyclerView>
                </LinearLayout>


            </android.support.design.widget.NavigationView>


        </android.support.v4.widget.DrawerLayout>










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

navigation_toolbarlayout.xml 该布局定义了toolbar上面代码中使用的代码

    <?xml version="1.0" encoding="utf-8"?>
    <android.support.design.widget.CoordinatorLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.design.widget.AppBarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:theme="@style/ThemeOverlay.AppCompat.ActionBar">

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@color/colorPrimary"
                android:minHeight="?attr/actionBarSize"
                app:titleTextColor="@android:color/white">

                <!-- Screen title -->
                <TextView
                    android:id="@+id/toolbarTitle"
                    style="@style/TextAppearance.AppCompat.Widget.ActionBar.Title"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:text=""
                    android:textColor="@android:color/white"></TextView>
            </android.support.v7.widget.Toolbar>
        </android.support.design.widget.AppBarLayout> …
Run Code Online (Sandbox Code Playgroud)

android android-linearlayout android-drawer

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

是否正在等待阻塞Android上的UI线程?

我一直在绕着协程包头,我在想以下代码。我在onCreate()上执行以下操作。

asyncJob = GlobalScope.launch(Dispatchers.Main) {
    val name = async(Dispatchers.Default) { queryDevices() }.await()
    mDeviceName.text = deviceName
}
Run Code Online (Sandbox Code Playgroud)

将执行顺序打印出来似乎是在UI线程上的“名称”之前,以及在设置名称后,它也在UI线程上。该queryDevicesMethod()是在后台线程预期。

但是我想知道在UI线程上调用await()时实际上在做什么吗?它会阻塞UI线程直到等待返回吗?

multithreading android coroutine kotlin kotlinx.coroutines

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

切换到另一个片段后使用 RunOnUIThread 导致空指针异常

public class ViewPagerTask extends TimerTask {
    @Override
    public void run() {
        getActivity().runOnUiThread(new Runnable() {
            @Override
            public void run() {
                if (viewPager.getCurrentItem() == 0){
                    viewPager.setCurrentItem(1);
                } else if (viewPager.getCurrentItem() == 1){
                    viewPager.setCurrentItem(2);
                } else  viewPager.setCurrentItem(0);
            }
        });
    }
}
Run Code Online (Sandbox Code Playgroud)

我正在使用此代码更改视图中的图像。但问题是我在片段中使用它,当我更改片段和应用程序运行几秒钟,然后突然弹出的空指针错误。现在我理解的原因是它试图更改图像但没有找到视图并创建此错误我不知道该怎么做。请帮忙 :)

错误

E/AndroidRuntime: FATAL EXCEPTION: Timer-0
Process: com.example.android.indianmetro, PID: 5150
java.lang.NullPointerException: Attempt to invoke virtual method 'void 
android.support.v4.app.FragmentActivity.runOnUiThread(java.lang.Runnable)' 
on a null object reference
    at com.example.android.indianmetro.HomeFragment$ViewPagerTask.run(HomeFragment.java:258)
at java.util.TimerThread.mainLoop(Timer.java:555)
at java.util.TimerThread.run(Timer.java:505)
E/AbstractTracker: Can't create handler inside thread that has not called 
Looper.prepare()
Run Code Online (Sandbox Code Playgroud)

android nullpointerexception android-runonuithread

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

片段内的按钮

嗨,我正在创建一个使用 aButton内部的应用程序Fragment,因此当我单击该应用程序时Button,该Button 将生成一个 Toast 文本,我Button改为使用单击侦听器。但问题是我Button没有响应点击,当我点击它时没有响应,Button所以我对它感到压力。这是我的主要问题的代码:

test = (Button) findViewById(R.id.button2);
t_layout = (TabLayout) findViewById(R.id.tabs);
t_layout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {

        @Override
        public void onTabSelected(TabLayout.Tab tab) {
            Fragment fragment;
            String contain = tab.getText().toString();
        if(contain.equals("POWER")){
                fragment = new power_fragment();
                FragmentManager fm = getFragmentManager();
                FragmentTransaction ft = fm.beginTransaction();
                ft.replace(R.id.fragment2, fragment);
                ft.commit();

                test.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        Toast.makeText(getApplicationContext(),"Test on",Toast.LENGTH_SHORT).show();
                             }
                          }
                       }
                    }
               });
Run Code Online (Sandbox Code Playgroud)

我正在使用 Tabitems,因此当我单击“POWER”的 Tabitem 时,Fragment将更改为包含 …

android android-fragments android-fragmentactivity android-studio android-tablayout

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

Android ListView滚动到底部

我正在开发带有聊天的应用程序,我希望我ListView在用户发布新消息时滚动到底部,当用户位于列表底部并收到新消息时.我用这个ListView:

<ListView
    android:id="@+id/list"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:divider="@null"
    android:dividerHeight="0dp"
    android:stackFromBottom="true"
    android:paddingBottom="9dp"
    android:clipToPadding="false"/>
Run Code Online (Sandbox Code Playgroud)

并且此方法在需要时强制滚动:

private void scrollListViewToBottom() {
        listView.setSelection(adapter.getCount() - 1);
}
Run Code Online (Sandbox Code Playgroud)

但是当聊天包含高度大于屏幕高度的元素(大文本或图像)时,它会滚动到它的顶部.我需要我ListView精确地滚动到底部,而不是最后一个元素.

我尝试使用listView.scrollTo(0, listView.getBottom())方法,但结果很奇怪 - 有时滚动到最后一条消息+半屏间隙,有时到我看不到任何消息的地方.

有任何想法吗?谢谢.

android listview scroll

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

如何在android中的relatvielayout里面的view viewr下面设置textview

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:weightSum="2"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">


    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:paddingLeft="55dp"
        android:paddingRight="55dp"
        android:paddingTop="55dp">

        <android.support.v4.view.ViewPager
            android:id="@+id/pager"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/pager"
            android:fontFamily="sans-serif"
            android:gravity="center_horizontal"
            android:lineSpacingExtra="6sp"
            android:paddingTop="30dp"
            android:text="@string/label_businesscard_title"
            android:textColor="#3e4360"
            android:textSize="16sp"
            android:textStyle="normal" />

        <com.viewpagerindicator.CirclePageIndicator
            android:id="@+id/indicator"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_centerHorizontal="true"
            android:paddingTop="15dp"
            app:centered="true"
            app:fillColor="#1ebad6"
            app:pageColor="#c6caca"
            app:snap="false" />
    </RelativeLayout>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:paddingLeft="20dp"
        android:paddingRight="20dp"
        android:paddingTop="40dp">


    </RelativeLayout>

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

这是我的xml我想在viewpager下面设置textview和textview下方的指示器我在下面放置功能布局但是它不起作用请建议我做错了什么.我期望的屏幕如下.

https://pasteboard.co/GSuVsth.jpg 但无法做到请建议我.

android

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

Gradle sync失败:找不到参数的方法compile()

我在添加新的依赖项后尝试gradle构建项目,build.gradle(Module.app)但得到以下错误.不知道我在这里做错了什么.

依赖试图添加:com.loopj.android:android-async-http:1.4.9

Gradle sync failed: Could not find method complie() for arguments [com.loopj.android:android-async-http:1.4.9] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
        Consult IDE log for more details (Help | Show Log)
Run Code Online (Sandbox Code Playgroud)

这是我的build.gradle档案

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion '25.0.2'

    defaultConfig {
        applicationId "com.londonappbrewery.climapm"
        minSdkVersion 16
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:25.3.1'
    complie 'com.loopj.android:android-async-http:1.4.9' …
Run Code Online (Sandbox Code Playgroud)

android build.gradle android-gradle-plugin

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

在 Edit Text android 上添加一个监听器?C#

我目前正在开发Android使用C#Xamarin

我的EditText应用程序中有一个框,用户可以在其中输入信息。如何添加一个监听器来查看用户是否真的在输入?我需要它的原因是将它链接到分析,这样我就可以看到有多少用户实际输入了信息。

谢谢!

c# android listener android-edittext xamarin

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

为什么加倍a =(double)('z'/'A')只给出C++中的整数部分?

我仍然是C++的初学者,所以我寻求一些基础知识的帮助.在这里,在下面的代码中,我使用类型转换来查找122/65的值,但即使是双数据类型,我也只得到整数部分.

#include <iostream>

using namespace std;

int main()

{

    double a=(double)('z'/'A');

    cout<<a;

    return 0;

}
Run Code Online (Sandbox Code Playgroud)

有人能为我提供一个很好的理由吗?

谢谢.

c++

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