text片段沟通(代码片段)

author author     2022-12-02     649

关键词:

package com.example.android.android_me.ui;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.Toast;

import com.example.android.android_me.R;

// This activity is responsible for displaying the master list of all images
// Implement the MasterListFragment callback, OnImageClickListener
public class MainActivity extends AppCompatActivity implements MasterListFragment.OnImageClickListener


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

    

    // Define the behavior for onImageSelected
    public void onImageSelected(int position) 
        // Create a Toast that displays the position that was clicked
        Toast.makeText(this, "Position clicked = " + position, Toast.LENGTH_SHORT).show();
    

package com.example.android.android_me.ui;

import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.GridView;

import com.example.android.android_me.R;
import com.example.android.android_me.data.AndroidImageAssets;


// This fragment displays all of the AndroidMe images in one large list
// The list appears as a grid of images
public class MasterListFragment extends Fragment 

    // Define a new interface OnImageClickListener that triggers a callback in the host activity
    OnImageClickListener mCallback;

    // OnImageClickListener interface, calls a method in the host activity named onImageSelected
    public interface OnImageClickListener 
        void onImageSelected(int position);
    

    // Override onAttach to make sure that the container activity has implemented the callback
    @Override
    public void onAttach(Context context) 
        super.onAttach(context);

        // This makes sure that the host activity has implemented the callback interface
        // If not, it throws an exception
        try 
            mCallback = (OnImageClickListener) context;
         catch (ClassCastException e) 
            throw new ClassCastException(context.toString()
                    + " must implement OnImageClickListener");
        
    


    // Mandatory empty constructor
    public MasterListFragment() 
    

    // Inflates the GridView of all AndroidMe images
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) 

        final View rootView = inflater.inflate(R.layout.fragment_master_list, container, false);

        // Get a reference to the GridView in the fragment_master_list xml layout file
        GridView gridView = (GridView) rootView.findViewById(R.id.images_grid_view);

        // Create the adapter
        // This adapter takes in the context and an ArrayList of ALL the image resources to display
        MasterListAdapter mAdapter = new MasterListAdapter(getContext(), AndroidImageAssets.getAll());

        // Set the adapter on the GridView
        gridView.setAdapter(mAdapter);

        // Set a click listener on the gridView and trigger the callback onImageSelected when an item is clicked
        gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() 
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) 
                // Trigger the callback method and pass in the position that was clicked
                mCallback.onImageSelected(position);
            
        );

        // Return the root view
        return rootView;
    

1. Define an interface in the fragment class that triggers a callbacl=k in the host activity
2. Ovveride the onAttach to make sure that the container acrivity has implemented the callback.
3. Set a click listener in the gridView and trigger the callback when an item is clicked
4. In the host activity implemenet the interface 
5. Define the bahavior inside the callback method

text为什么良好的沟通至关重要-杰弗里麦克斯韦(代码片段)

查看详情

儿童片段到父母片段沟通(代码片段)

在我的孩子片段中,我有一个Recyclerview,我的父片段中有一个Appbar布局。当Recyclerview第一个项目可见时,我需要更新父片段中的appbar布局我的界面publicinterfaceOnListFirstItemVisibleListenerpublicvoidsendDataToFragmentOnFirstItemVisible(booleandata,intd... 查看详情

markdown关于沟通技巧的最佳书籍(代码片段)

查看详情

python与arduino沟通以为是串口(代码片段)

查看详情

软件测试的三个沟通技巧(代码片段)

成熟的沟通技巧对于软件测试工程师在竞争激烈的软件测试领域中发挥作用至关重要。虽然软件测试职业需要编程技术和业务能力等硬技能,但优秀的测试人员是全面的,并且掌握了人际沟通的艺术。能够有效在团队以及与外部... 查看详情

项目沟通管理和干系人管理(代码片段)

项目沟通管理是确保及时、正确地处理项目信息所需的过程。项目经理需要花费大量的、无规律的时间与各方进行沟通、联络。所谓各方,其中最重要的就是项目干系人。一、项目沟通管理基础1、项目沟通管理的重要性IT项... 查看详情

做更好的职场人理性弹性开放的沟通(代码片段)

好一段时间没逛茶馆了。看到这个随笔,正合自己口味,就谈点自己的经历和想法吧。我想说的是沟通的事情。不是因为我自己的沟通能力有多好,而是因为自己经历了一个沟通由不好变得更好的过程。这其中有来自小伙伴的宽... 查看详情

前后端沟通namingconversion转换需要知道的事(代码片段)

c#是pascalcase,js是camelcase所以在做webapi和odata的时候经常需要转换. 早年webapi是依赖Newtonsoftjson(JSON.NET)的,所以我们常看见 [JsonProperty(propertyName:"name_cn")]publicstringNameget;set;="";或者 [DataMember(Name 查看详情

text片段(代码片段)

查看详情

text片段(代码片段)

查看详情

text片段(代码片段)

查看详情

text代码片段很有用(代码片段)

查看详情

text代码片段【snl】(代码片段)

查看详情

text测试片段(代码片段)

查看详情

text主片段(代码片段)

查看详情

text测试片段(代码片段)

查看详情

text生活片段(代码片段)

查看详情

text数学片段(代码片段)

查看详情