小编The*_*man的帖子

按钮在Android应用程序中不起作用

我是Android的新手,并试图实现一个简单的按钮,它应该在Toast中显示一条消息(最终它将用于创建一个帐户).但是当我按下按钮没有任何反应时,logcat上没有显示任何错误,所以我必须错过一些明显的东西,但我找不到它!

AndroidManifest.xml中

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.laptop.whatsfordinner" >

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <!--Splash Screen -->
    <activity
        android:name=".Splash"
        android:label="@string/app_name"
        android:screenOrientation="portrait"
        android:theme="@android:style/Theme.Black.NoTitleBar" >
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />

        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
    </activity>

    <activity
        android:name=".MainPage"
        android:label="@string/app_name" >

    </activity>

    <!--Register User -->
    <activity
        android:name=".RegistrationActivity"
        android:label="Register User">
    </activity>
</application>

<!--  Internet Permissions -->
<uses-permission android:name="android.permission.INTERNET" />

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

registration.xml

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

    <!-- Name Label -->
    <TextView android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/reg_title1"
        android:paddingLeft="10dip"
        android:paddingRight="10dip"
        android:paddingTop="10dip"
        android:textSize="17sp"/>

    <!-- Input Name …
Run Code Online (Sandbox Code Playgroud)

java android

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

switch语句的复杂多个案例

在我的程序中,我要求用户输入数组的大小,然后用用户输入的数字填充数组.

然后用户输入一个数字,该数字将检查它是否存在于数组中.如果是,它将向控制台输出一条消息.

我希望能够根据数组中数字的位置打印不同的消息.

如果是第1日,第21日,第31日等,则会打印出不同的信息

如果它是第2,第22,第32等......将打印不同的信息

如果它是第3个,第23个,第33个等......将打印不同的消息

然后默认情况是如果它是"th"数字之一,将打印不同的消息

这是我的代码的一部分,它只适用于前10个数字.我遇到的问题是,11日,12日,13日不遵循正常规则,任何以11,12或13结尾的数字都是如此.

Console.Write("Now enter a number to compare: ");
int c = Convert.ToInt32(Console.ReadLine());
int pos = Array.IndexOf(arr, c);

if (pos > -1)
{
    switch (pos)
    {
        case 0:
            Console.WriteLine("{0} is the {1}st number in this list", c, pos + 1);
            break;

        case 1:
            Console.WriteLine("{0} is the {1}nd number in this list", c, pos + 1);
            break;

        case 2:
            Console.WriteLine("{0} is the {1}rd number in this list", c, pos + 1);
            break;

        default:
            Console.WriteLine("{0} is …
Run Code Online (Sandbox Code Playgroud)

c# arrays switch-statement

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

c# - 如何遍历字典并比较值?

我正在教自己c#并在我自己的迷你项目上工作.程序使用随机数填充数组,程序返回数字(0-15)以及它在数组中出现的次数.我将这些值存储在字典中,因为我想对值进行排序而不会丢失映射到它的键.

然后将排序的值存储到另一个字典中,现在我希望能够遍历字典并获得具有最高值的密钥.换句话说,向控制台打印出现次数最多的数字.在对字典进行排序时,最后一个数字将是最高值.

但是,对于大多数情况,可能会有多个数字并列,而这就是我坚持的地方.如果数字4,5,6,7都出现次数最多,我希望能够将其打印到控制台.

      Dictionary<int, int> dic = new Dictionary<int, int>();
      //iterates through numbers 0-15
      for (int y = 0; y <= 15; y++)
       {   
            int m = 0;
            //iterates through entire array
            for (int i = 0; i < Arr.Length; i++)
            { 
                //comparisons 
                if (y == Arr[i])
                {
                    m++;

                }

            }
            //Inserts number and count into the dictionary
            dic.Add(y,m);

        }
        //Sorts the dictionary and adds the sorted one into a new dictionary
        Dictionary<int, int> dic2 = new Dictionary<int, int>();
        foreach …
Run Code Online (Sandbox Code Playgroud)

c# dictionary

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

c# - 分别打印字典的键和值

我有一个包含键和值的字典.我想打印到控制台的键和值.但我想分别打印键和值.y是唯一的,m是分配给键的值.

看到我在这里尝试如何做到这一点,但我得到一个错误说

预期方法,代表或事件

码:

List<int> col = new List<int>();
Dictionary<int, int> dic = new Dictionary<int, int>();
//iterates through min-max
for (int y = 0; y <= 15; y++)
   {   
 int m = 0;
   //iterates through array
      for (int i = 0; i < Arr.Length; i++)
         { 
            //comparisons
              if (y == Arr[i])
              {
                 m++;

               }

           }
 dic.Add(y,m);  
 Console.WriteLine("Number {0} appears {1} times ", y, dic[y]);
Run Code Online (Sandbox Code Playgroud)

c# dictionary

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

标签 统计

c# ×3

dictionary ×2

android ×1

arrays ×1

java ×1

switch-statement ×1