RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / user-464669

МастерОК's questions

Martin Hope
МастерОК
Asked: 2023-10-30 02:58:56 +0000 UTC

如何编辑dll文件?

  • 1

我最近下载了一个CSS作弊程序,但在游戏过程中它不断地在聊天中向VK开发人员发送链接(据我所知,这是因为这是一个免费版本)。所以,我想从这个dll中删除这段文本(或者至少用空格替换它),我什至设法通过IDA找到了这一行的存储位置。但是我怎样才能编辑它并编译回dll呢?

dll
  • 1 个回答
  • 58 Views
Martin Hope
МастерОК
Asked: 2022-08-30 14:57:17 +0000 UTC

java.lang.IllegalArgumentException:运行片段时找不到 id 的视图

  • 0

大家好。在这里,我决定开始掌握像 Fragment 这样的 UI 元素,但是我出了点问题。事实是,我创建了一个在启动时打开一个空 Fragment 的应用程序,但该应用程序立即崩溃并出现以下错误:

java.lang.IllegalArgumentException: No view found for id 0x7f080155 com.masterok.testapp:id/placeHolder) for fragment MainFragment{f9b5608} (4b1096cb-a0bc-4cc0-a9ff-2975f29359ce id=0x7f080155)(com.masterok.testapp:id/placeHolder) for fragment MainFragment{f9b5608} (4b1096cb-a0bc-4cc0-a9ff-2975f29359ce id=0x7f080155)
        at androidx.fragment.app.FragmentStateManager.createView(FragmentStateManager.java:513)
        at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:282)
        at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:2189)
        at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:2100)
        at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:2002)
        at androidx.fragment.app.FragmentManager.dispatchStateChange(FragmentManager.java:3138)
        at androidx.fragment.app.FragmentManager.dispatchActivityCreated(FragmentManager.java:3072)
        at androidx.fragment.app.FragmentController.dispatchActivityCreated(FragmentController.java:251)
        at androidx.fragment.app.FragmentActivity.onStart(FragmentActivity.java:502)
        at androidx.appcompat.app.AppCompatActivity.onStart(AppCompatActivity.java:246)
        at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1473)
        at android.app.Activity.performStart(Activity.java:8082)
        at android.app.ActivityThread.handleStartActivity(ActivityThread.java:3732)
        at android.app.servertransaction.TransactionExecutor.performLifecycleSequence(TransactionExecutor.java:221)
        at android.app.servertransaction.TransactionExecutor.cycleToPath(TransactionExecutor.java:201)
        at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:173)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2253)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loopOnce(Looper.java:201)
        at android.os.Looper.loop(Looper.java:288)
        at android.app.ActivityThread.main(ActivityThread.java:7870)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:550)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)

如何解决这个问题呢?MainActivity 和 MainFragment 代码如下:

活动主.xml:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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"
    tools:context=".MainActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

MainActivity.kt:

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        supportFragmentManager
            .beginTransaction()
            .replace(R.id.placeHolder, MainFragment.newInstance())
            .commit()
    }
}

片段主.xml:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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:id="@+id/placeHolder"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".fragments.MainFragment">
    
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Fragment1"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

MainFragment.kt:

class MainFragment : Fragment() {
    private lateinit var binding: FragmentMainBinding

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View {
        binding = FragmentMainBinding.inflate(inflater, container, false)
        return binding.root
    }

    companion object {
        @JvmStatic
        fun newInstance() = MainFragment()
    }
}
android
  • 2 个回答
  • 48 Views
Martin Hope
МастерОК
Asked: 2022-08-11 01:54:08 +0000 UTC

OnTriggerEnter2D 功能在 Unity2d 中不起作用和延迟

  • 0

大家好。我决定在 Unity 中制作 2d 游戏,但我遇到了问题。游戏的本质是你需要控制角色并收集硬币,硬币应该每两秒出现在随机位置,当角色接触它们时应该消失。但问题是,当角色接触硬币时,OnTriggerEnter2D 事件不会触发,延迟函数“Thread.Sleep();”也不起作用。当我将它添加到代码并开始游戏时,Unity 冻结并且不响应任何点击。如何使用 OnTriggerEnter2D 和 Thread.Sleep() 解决这两个问题;

代码如下:

GameController.cs(其中包含每两秒生成硬币的代码):

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Threading;
using System.Threading.Tasks;

public class GameController : MonoBehaviour
{
    public GameObject coin;
    public static GameObject inst_obj;


    private void SpawnCoin()
    {
        int randY = Random.Range(5, -6);
        int randX = Random.Range(-3, 3);
        Vector3 spawnPosition = new Vector3(randX, randY);
        Quaternion spawnRotation = Quaternion.identity;
        inst_obj = Instantiate(coin, spawnPosition, spawnRotation) as GameObject;

    }
    private void FixedUpdate()
    {
        Thread.Sleep(2000);
        SpawnCoin();
    }
}

这是 Player.cs 脚本(包含相同的 OnTriggerEnter2D):

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

using UnityEngine.UI;
using UnityEngine.SceneManagement;
using System.Threading;
using System;
using System.Threading.Tasks;

public class Player : MonoBehaviour
{
    
    public FixedJoystick joystick;
    public float velocity = 1.0f;
    public float velocityRightLeft = 1.0f;
    private int coins1 = 0;
   
    //GameController gameController = new GameController();
    // Start is called before the first frame update
    void Start()
    {
         
    }

    // Update is called once per frame
    void FixedUpdate()
    {      
            gameObject.GetComponent<Rigidbody2D>().transform.position += new Vector3(joystick.Direction.x * velocityRightLeft * Time.fixedDeltaTime, joystick.Direction.y * velocity * Time.fixedDeltaTime, 0);
        
    }
    private  void OnTriggerEnter2D(Collider2D other)
    {
        if (other.tag.Equals("Coin"))
        {
            Destroy(GameController.inst_obj);
        }
    }



}
c# unity3d
  • 1 个回答
  • 33 Views
Martin Hope
МастерОК
Asked: 2022-07-16 21:59:53 +0000 UTC

NullReferenceException:开始动画时未将对象引用设置为对象的实例[重复]

  • 0
这个问题已经在这里得到了回答:
什么是 NullReferenceException,如何修复代码? (2 个回答)
7 个月前关闭。

有一个类player包含停止( stopPlayerAnim) 和启动( startPlayerAnim) 播放器动画的功能,以及启动Joystic它们的类。但是当我按下操纵杆时,游戏崩溃并出现以下错误:

NullReferenceException:对象引用未设置为对象的实例 player.startPlayerAnim ()(位于 Assets/scripts/player.cs:46)Joystic.OnDrag (UnityEngine.EventSystems.PointerEventData eventData)(位于 Assets/scripts/Joystic.cs: 13) UnityEngine.EventSystems.ExecuteEvents.Execute (UnityEngine.EventSystems.IDragHandler handler, UnityEngine.EventSystems.BaseEventData eventData) (在Library/PackageCache/com.unity.ugui@1.0.0/Runtime/EventSystem/ExecuteEvents.cs:71) UnityEngine.EventSystems.ExecuteEvents.Execute[T](UnityEngine.GameObject 目标,UnityEngine.EventSystems.BaseEventData eventData,UnityEngine.EventSystems.ExecuteEvents+EventFunction`1[T1] 函子)(在 Library/PackageCache/com.unity.ugui@1.0 .0/Runtime/EventSystem/ExecuteEvents.cs:262) UnityEngine.EventSystems.EventSystem:Update()(在 Library/PackageCache/com.unity.ugui@1.0。0/运行时/EventSystem/EventSystem.cs:385)>

错误指的是这一行:player1.GetComponent<Animator>().SetBool("ball_anim", true);

是什么原因造成的,如何消除?上述脚本的代码如下:

播放器.cs:

public class player : MonoBehaviour
{
  
    public static GameObject player1;
    
    void Start()
    {
     
    }
    
    public static void startPlayerAnim()
    {

        player1.GetComponent<Animator>().SetBool("ball_anim", true);
        player1.GetComponent<Animator>().SetBool("inverted_ball_anim", false);
    }

    public static void stopPlayerAnim()
    {

        player1.GetComponent<Animator>().SetBool("ball_anim", false);
        player1.GetComponent<Animator>().SetBool("inverted_ball_anim", false);
    }

    public static void startInvertedPlayerAnim()
    {
        player1.GetComponent<Animator>().SetBool("inverted_ball_anim", true);
        player1.GetComponent<Animator>().SetBool("ball_anim", false);

    }
   
    

  
    

   

    
}
c#
  • 1 个回答
  • 10 Views
Martin Hope
МастерОК
Asked: 2022-06-08 16:22:36 +0000 UTC

如何在android中按时间实现通知?

  • 0

我有一个带注释的应用程序。我在那里添加了通知(显示在状态栏中)。为了测试,我做了这样的设置,当您单击“绿色”按钮时,应用程序不仅会更改背景,还会向用户发送通知。但我想确保通知不是通过按下按钮发送给用户,而是在某个时间(例如,17:00)自动发送给用户,即使他没有打开应用程序。我该如何实施?为此,我提前准备了一个 BootCompletedReceiver,以便在设备启动后自动启动应用程序。接收者和通知代码将在下面。

引导完成接收器:

public class BootCompletedReceiver extends BroadcastReceiver {

    public BootCompletedReceiver() {
    }
    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {

        }
    }
}

发送通知代码:

...

public void onClickGreen(View view) { 
        Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            v.vibrate(VibrationEffect.createOneShot(500, VibrationEffect.DEFAULT_AMPLITUDE));
        } else {
            
            v.vibrate(500);
        }
        Intent notificationIntent = new Intent(Options.this, Options.class);
        PendingIntent contentIntent = PendingIntent.getActivity(Options.this,
                0, notificationIntent,
                PendingIntent.FLAG_CANCEL_CURRENT);
        Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        NotificationCompat.Builder builder =
                new NotificationCompat.Builder(Options.this, CHANNEL_ID)
                        .setSmallIcon(R.drawable.ikon_for_calendar_1)
                        .setContentTitle("Напоминание")
                        .setContentText("Пора проверить заметки!")
                        .setSound(defaultSoundUri)
                        .setPriority(NotificationCompat.PRIORITY_DEFAULT)
                        .setContentIntent(contentIntent)

                        .setAutoCancel(true); // автоматически закрыть уведомление после нажатия



        NotificationManagerCompat notificationManager =
                NotificationManagerCompat.from(Options.this);
        notificationManager.notify(NOTIFY_ID, builder.build());


    }
java
  • 1 个回答
  • 10 Views
Martin Hope
МастерОК
Asked: 2022-05-17 23:16:08 +0000 UTC

错误 setData(java.lang.String, java.lang.String) 不能应用于 (java.lang.String)

  • 0

大家好。我有一个笔记应用程序。我决定在其中添加每个笔记创建时间的显示。一切都差不多了,但是在MainAdapter文件(RecyclerView的适配器,显示笔记列表)中出现了错误,即在holder.setData(mainArray.get(position).getTitle());A行,错误如下:'setData(java.lang.String, java.lang. 'com.masterok.calendar.adapter.MainAdapter.MyViewHolder' 中的 String)' 不能应用于 '(java.lang.String)' 是什么导致了这个错误,我该如何解决?我给出下面的代码:

MainAdapter.java:

package com.masterok.calendar.adapter;

import android.content.Context;
import android.content.Intent;


import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.masterok.calendar.EditActivity;
import com.masterok.calendar.R;
import com.masterok.calendar.db.MyConstants;
import com.masterok.calendar.db.MyDbManager;

import java.util.ArrayList;
import java.util.List;

public class MainAdapter extends RecyclerView.Adapter <MainAdapter.MyViewHolder> {
    private final Context context;
    private final List<ListItem> mainArray;

    public MainAdapter(Context context) {
        this.context = context;
        mainArray = new ArrayList<>();
    }

    @NonNull
    @Override
    public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_list_layout, parent,false);
        return new MyViewHolder(view, context, mainArray);

    }

    @Override
    public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
    holder.setData(mainArray.get(position).getTitle());

    }

    @Override
    public int getItemCount() {
        return mainArray.size();
    }

    static class MyViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{
    private final TextView tvTitle;
    private final TextView tvTime;
    private final Context context;
    private final List<ListItem> mainArray;

        public MyViewHolder(@NonNull View itemView, Context context, List<ListItem> mainArray) {
            super(itemView);
            this.context = context;
            this.mainArray = mainArray;
            tvTitle = itemView.findViewById(R.id.tvTitle);
            tvTime = itemView.findViewById(R.id.tvTime);
            itemView.setOnClickListener(this);

        }


        @Override
        public void onClick(View v) {
            Intent i = new Intent(context, EditActivity.class);
            i.putExtra(MyConstants.LIST_ITEM_INTENT, mainArray.get(getAdapterPosition()));
            i.putExtra(MyConstants.EDIT_STATE, false);
            context.startActivity(i);


        }


        public void setData(String title, String time) {
            tvTitle.setText(title);
            tvTime.setText(time);
        }
    }
    public void updateAdapter(List<ListItem> newList){
        mainArray.clear();
        mainArray.addAll(newList);
        notifyDataSetChanged();

    }

    public void removeItem(int pos, MyDbManager dbManager){
        dbManager.delete(mainArray.get(pos).getId());
        mainArray.remove(pos);
        notifyItemRangeChanged(0, mainArray.size());
        notifyItemRemoved(pos);


    }

}

EditActivity.java(添加/编辑笔记屏幕):

package com.masterok.calendar;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.constraintlayout.widget.ConstraintLayout;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;

import android.view.View;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.Toast;

import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.masterok.calendar.adapter.ListItem;
import com.masterok.calendar.db.AppExecutor;
import com.masterok.calendar.db.MyConstants;
import com.masterok.calendar.db.MyDbManager;


import java.text.SimpleDateFormat;

import java.util.Date;

public class EditActivity extends AppCompatActivity {
    private final int PICK_IMAGE_CODE = 123;
    private ImageView imNewImage;
    private ConstraintLayout imageContainer;
    private ImageButton imEditImage, imDeleteImage;
    private FloatingActionButton fbAddImage;
    private EditText edTitle, edDesc;
    private MyDbManager myDbManager;
    private String tempUri = "empty";
    private boolean isEditState = true;
    private ListItem item;


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



    }

    private void init() {
        myDbManager = new MyDbManager(this);
        edTitle = findViewById(R.id.edTitle);
        imNewImage = findViewById(R.id.imNewImage);
        fbAddImage = findViewById(R.id.fbAddImage);
        imageContainer = findViewById(R.id.imageContainer);
        imEditImage = findViewById(R.id.imEditImage);
        imDeleteImage = findViewById(R.id.imDeleteImage);
        edDesc = findViewById(R.id.edDesc);
    }

    private void getMyIntents() {
        Intent i = getIntent();
        if (i != null) {
            item = (ListItem) i.getSerializableExtra(MyConstants.LIST_ITEM_INTENT);
            isEditState = i.getBooleanExtra(MyConstants.EDIT_STATE, true);

            if (!isEditState) {
                edTitle.setText(item.getTitle());
                edDesc.setText(item.getDesc());
                if (!item.getUri().equals("empty")) {
                    tempUri = item.getUri();
                    imageContainer.setVisibility(View.VISIBLE);
                    imNewImage.setImageURI(Uri.parse(item.getUri()));
                    imDeleteImage.setVisibility(View.GONE);
                    imEditImage.setVisibility(View.GONE);

                }

            }

        }

    }


    public void onResume() {
        super.onResume();

    }

    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        if (resultCode == RESULT_OK && requestCode == PICK_IMAGE_CODE && data != null) {

            tempUri = data.getData().toString();
            imNewImage.setImageURI(data.getData());
            getContentResolver().takePersistableUriPermission(data.getData(), Intent.FLAG_GRANT_READ_URI_PERMISSION);


        }

    }


    public void onClickSave(View view) {

        final String title = edTitle.getText().toString();
        final String desc = edDesc.getText().toString();
        if (title.equals("") || desc.equals("")) {
            Toast.makeText(this, R.string.empty, Toast.LENGTH_LONG).show();
        } else {
            if (isEditState) {
                myDbManager.openDb();
                AppExecutor.getInstance().getSubIO().execute(new Runnable() {
                    @Override
                    public void run() {
                        myDbManager.insertToDb(title, desc, tempUri, getCurrentTime());
                    }
                });
                Toast.makeText(this, R.string.saved, Toast.LENGTH_LONG).show();

            } else {
                myDbManager.openDb();
                myDbManager.updateItem(title, desc, tempUri, item.getId(), getCurrentTime());
                Toast.makeText(this, R.string.saved, Toast.LENGTH_LONG).show();

            }
            myDbManager.closeDb();
            finish();

        }
    }

    public void onBackPressed () {
        super.onBackPressed();

        final String title = edTitle.getText().toString();
        final String desc = edDesc.getText().toString();
        if (title.equals("") || desc.equals("")) {
            Toast.makeText(this, R.string.empty, Toast.LENGTH_LONG).show();
        } else {
            if (isEditState) {
                myDbManager.openDb();
                AppExecutor.getInstance().getSubIO().execute(new Runnable() {
                    @Override
                    public void run() {
                        myDbManager.insertToDb(title, desc, tempUri, getCurrentTime());
                    }
                });
                Toast.makeText(this, R.string.saved, Toast.LENGTH_SHORT).show();

            } else {
                myDbManager.openDb();
                myDbManager.updateItem(title, desc, tempUri, item.getId(), getCurrentTime());
                Toast.makeText(this, R.string.saved, Toast.LENGTH_LONG).show();

            }
            myDbManager.closeDb();
            finish();

        }
    }




    public void onClickDeleteImage(View view) {

        imNewImage.setImageResource(R.drawable.ic_image_def);
        tempUri = "empty";
        imageContainer.setVisibility(View.GONE);
        fbAddImage.setVisibility(View.VISIBLE);
    }

    public void onClickAddImage(View view) {
        imageContainer.setVisibility(View.VISIBLE);
        view.setVisibility(View.GONE);

    }

    public void onClickChooseImage(View view) {
        Intent chooser = new Intent(Intent.ACTION_OPEN_DOCUMENT);
        chooser.setType("image/*");
        startActivityForResult(chooser, PICK_IMAGE_CODE);

    }
    private String getCurrentTime(){
        Date date = new Date();
        SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
        return formatter.format(date);



    }


}

Listitem.java:

package com.masterok.calendar.adapter;

import java.io.Serializable;

public class ListItem implements Serializable {
    private String title;
    private String desc;
    private String uri = "empty";
    private String time = "";

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    private int id = 0;

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getDesc() {
        return desc;
    }

    public void setTime(String time) {
        this.time = time;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    public String getUri() {
        return uri;
    }

    public void setUri(String uri) {
        this.uri = uri;
    }
}
java
  • 1 个回答
  • 10 Views
Martin Hope
МастерОК
Asked: 2022-10-10 01:03:13 +0000 UTC

无法通过对话框清除 SharedPreferences

  • 0

我决定通过对话框将 SharedPreferences 清除功能(其中存储笔记)与日历和笔记一起添加到我的应用程序中,但是出了点问题:当单击对话框中的“确定”按钮时,笔记应该已被清除,但由于某种原因,没有发生清除(没有出现错误),即使我使用以下命令确认了这一点:

editor.apply();

activity_notes.xml 代码:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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"
    tools:context="Notes">

    <ImageButton
        android:id="@+id/imageButton3"
        android:layout_width="83dp"
        android:layout_height="73dp"
        android:layout_marginStart="1dp"
        android:layout_marginLeft="1dp"
        android:layout_marginBottom="5dp"
        android:contentDescription="@string/addnote"

        android:onClick="addnote"
        android:src="@android:drawable/ic_input_add"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        tools:ignore="ImageContrastCheck" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="279dp"
        android:layout_marginBottom="324dp"
        android:orientation="vertical"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <TextView
            android:id="@+id/final_text"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
    </LinearLayout>

    <TextView
        android:id="@+id/notesView"
        android:layout_width="410dp"
        android:layout_height="468dp"
        android:text=""
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <ImageButton
        android:id="@+id/clear_notes"
        android:layout_width="65dp"
        android:layout_height="55dp"
        android:layout_marginStart="335dp"
        android:layout_marginLeft="335dp"
        android:layout_marginTop="538dp"
        android:layout_marginEnd="11dp"
        android:layout_marginRight="11dp"
        android:layout_marginBottom="10dp"
        android:contentDescription="@string/delete_notes"
        android:onClick="clear_notes"
        android:src="@android:drawable/ic_menu_delete"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        tools:ignore="SpeakableTextPresentCheck" />

</androidx.constraintlayout.widget.ConstraintLayout>

Notes.java 代码(如果有的话,方法中用于清除注释的代码clear_notes):

package com.masterok.calendar;



import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;


import android.widget.EditText;
import android.widget.ImageButton;


import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;


public class Notes extends AppCompatActivity {

    final Context context = this;
    final Context context1 = this;
    public ImageButton button;
    public TextView final_text;
    public SharedPreferences pref;
    public EditText input_text;
    public TextView notesView;
    public final String save_key = "save note";





    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_notes);

        notesView = (TextView)findViewById(R.id.notesView);
        button = findViewById(R.id.imageButton3);
        final_text =  findViewById(R.id.final_text);

        init();}

    public void init(){
        pref = getSharedPreferences( "note",MODE_PRIVATE);
        input_text = findViewById (R.id.input_text);
        notesView.setText(pref.getString(save_key,"You haven`t got any note"));

    }

    public void clear_notes(View arg0){

        LayoutInflater li = LayoutInflater.from(context1);
        View promptsView = li.inflate(R.layout.deleting_notes, null);

        AlertDialog.Builder mDialogBuilder = new AlertDialog.Builder(context1);
        mDialogBuilder.setView(promptsView);
        mDialogBuilder
                .setCancelable(false)
                .setPositiveButton("OK",
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog,int id) {

                                SharedPreferences sharedPrefs = context.getSharedPreferences(save_key, MODE_PRIVATE);
                                SharedPreferences.Editor editor = sharedPrefs.edit();
                                editor.apply();
                                editor.remove(save_key );
                                editor.apply();
                            }
                        })
                .setNegativeButton("Cancel",
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog,int id) {
                                dialog.cancel();
                            }
                        });

        AlertDialog alertDialog = mDialogBuilder.create();

        alertDialog.show();
    }



        public void addnote(View arg0) {

            LayoutInflater li = LayoutInflater.from(context);
            View promptsView = li.inflate(R.layout.prompt, null);

            AlertDialog.Builder mDialogBuilder = new AlertDialog.Builder(context);

            mDialogBuilder.setView(promptsView);

            final EditText userInput = promptsView.findViewById(R.id.input_text);

            mDialogBuilder
                    .setCancelable(false)
                    .setPositiveButton("OK",
                            new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog,int id) {

                                    final_text.setText(userInput.getText());
                                    SharedPreferences.Editor edit = pref.edit();
                                    edit.putString(save_key,final_text.getText().toString());
                                    edit.apply();
                                    notesView.setText(pref.getString(save_key,"You haven`t got any note"));
                                }
                            })
                    .setNegativeButton("Cancel",
                            new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog,int id) {
                                    dialog.cancel();
                                }
                            });

            
            AlertDialog alertDialog = mDialogBuilder.create();

           
            alertDialog.show();
            }


}

Prompt.xml 代码(这是添加注释对话框):

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/layout_root"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:padding="10dp" >
    <TextView
        android:id="@+id/tv"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/write_the_note"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <EditText
        android:id="@+id/input_text"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        >

        <requestFocus />
    </EditText>
</LinearLayout>

delete_notes.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="match_parent">

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="@string/do_you_want_to_clear_notes" />
</LinearLayout>

请告诉我如何解决这个问题。

java
  • 1 个回答
  • 10 Views

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    我看不懂措辞

    • 1 个回答
  • Marko Smith

    请求的模块“del”不提供名为“default”的导出

    • 3 个回答
  • Marko Smith

    "!+tab" 在 HTML 的 vs 代码中不起作用

    • 5 个回答
  • Marko Smith

    我正在尝试解决“猜词”的问题。Python

    • 2 个回答
  • Marko Smith

    可以使用哪些命令将当前指针移动到指定的提交而不更改工作目录中的文件?

    • 1 个回答
  • Marko Smith

    Python解析野莓

    • 1 个回答
  • Marko Smith

    问题:“警告:检查最新版本的 pip 时出错。”

    • 2 个回答
  • Marko Smith

    帮助编写一个用值填充变量的循环。解决这个问题

    • 2 个回答
  • Marko Smith

    尽管依赖数组为空,但在渲染上调用了 2 次 useEffect

    • 2 个回答
  • Marko Smith

    数据不通过 Telegram.WebApp.sendData 发送

    • 1 个回答
  • Martin Hope
    Alexandr_TT 2020年新年大赛! 2020-12-20 18:20:21 +0000 UTC
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +0000 UTC
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5