在ExpandableListview的childview中的textview的底部动态添加图像

时间:2018-07-28 12:36:10

标签: android android-layout imageview expandablelistview

我想最好先解释一下我的目标,我正在尝试为不同的病理情况创建不同的消耗性清单。 在疾病的每个可扩展列表中,都有某些元素(子列表)包含文本(texview)和图像(imageview或cardeview,我很困惑,因为我必须添加图像标题,而我猜cardview是其中之一)。我有近40张照片。 所有子清单都有文字。但有些子清单将有一张或多张照片,有些则将没有。

我的问题是如何在子列表的textview的末尾或中间将图像添加到子列表(如上一段所述)?

请帮助我,我在互联网上搜索时没有找到答案。 例如,这就是我想要达到的目标(医疗应用的屏幕截图):

An image at the end of textview ..that when clicked on..it get pop up with zoom

another screenshot for the same app and for the same page showing the strcuture

这是我到目前为止所拥有的: image from the emulator


主要活动。java

package ma.ac.iav.myapplication;
    import android.support.v4.widget.DrawerLayout;
    import android.support.v7.app.ActionBarDrawerToggle;
    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;
    import android.view.MenuItem;
    import android.widget.ExpandableListView;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
public class MainActivity extends AppCompatActivity {

    private ExpandableListView listView;
    private ExpendableListAdapter listAdapter;
    private List<String> listdataheader;
    private HashMap<String,List<String>> listHash;


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

        listView=(ExpandableListView)findViewById(R.id.acitivitylistview);
        initData();
        listAdapter=new ExpendableListAdapter(this,listdataheader,listHash);
        listView.setAdapter(listAdapter);
    }

    private void initData() {
        listdataheader=new ArrayList<>();
        listHash=new HashMap<>();

        listdataheader.add("OVERVIEW");
        listdataheader.add("EXTERNAL FEATURES OF THE NOSTRILS");
        listdataheader.add("NASAL VESTIBULE");
        listdataheader.add("CARTILAGINOUS FRAMEWORKk");
        listdataheader.add("MUSCULATURE");
        listdataheader.add("TEGUMENT");
        listdataheader.add("BLOOD SUPPLY");
        listdataheader.add("VENOUS DRAINAGE");
        listdataheader.add("LYMPHATIC DRAINAGE");
        listdataheader.add("NERVES");

        List<String> overview=new ArrayList<>();
        overview.add("The nostrils (or anterior nares), depending on the needs, can increase their diameter permitting reduction of resistance to flow thereby facilitating high airflow rates (e.g. exercise), or can closes preventing entry of undesired substances (e.g. water during swimming). It is noteworthy that the nostrils alone contribute more than 50% to the overall resistance to flow of the entire upper respiratory tract throughout quiet breathing. ");


        List<String> externalfeatures =new ArrayList<>();
        externalfeatures.add("The nostrils are placed obliquely in the dorsocaudal direction, so that distance between the two ventral commissures is shorter than that between the two dorsal commissures. They are bounded by two alae or wings (Alae nasi), which meets above and below at the level of commissures. \n" +
                "-\tThe lateral ala is concave, adjacent to the upper lip. It is covered by a fold very incompletely supported by cartilaginous formations (allowing greater mobility), in which project the cornu of the alar cartilage for a short distance below and behind the ventral commissure;\n" +
                "-\tThe dorsomedial ala, is convex, supported and elevated by lamina of the alar cartilage;\n" +
                "-\tThe ventral commissure is wide and rounded; \n" +
                "-\tThe dorsal commissure is straight and narrow, being elevated dorsally so the nostril draws a comma. It is prolonged by a very deep groove (sulcus alaris), which gives access to the nasal diverticulum (or false nostril).\n" +
                "The rostrum or the tip of the nose corresponds to the rostral extremity of the face. It separates and overcomes the nostrils. It is divided by a vertical groove, very little marked in equines: the Philtrum.\n");

        List<String> nasalvestibule =new ArrayList<>();
        nasalvestibule.add("The nasal vestibule (vestibulum nasi) is located at the entrance of the nasal cavities. It is enclosed by the two alae and the mobile part of the nasal septum (Pars mobilis septi nasi) which can be palpated between the two nostrils. \n" +
                "The thick alar fold (plica aris), a mucosal extension of the ventral turbinate, divides each naris into dorsal and ventral parts. The dorsal part leads into a blind, hair-lined cavity known as the false nostril (or nasal diverticulum), which extends backwards to nasoincisive notch formed by the incisive bone ventrally and the nasal bone dorsally. It is approximately 10 cm in depth and its function is unknown. The ventral part of the naris leads directly into the nasal cavity.\n" +
                "The junction between the skin and the nasal mucosa, or limen nasi, is visible just within the external nares, it is marked by a rapid change in structure and color (from black to bright red). On the ventral aspect of this mucocutaneous junction is the opening of the nasolacrimal duct (ostium nasolacrimale), it is not rare to find one or two accessory orifices. This is one source of the small amount of moisture frequently seen on the horse’s external nares.\n");

        List<String> cartilagineousframework =new ArrayList<>();
        cartilagineousframework.add("The cartilaginous framework of nostril of the horse consist of three cartilages: two are principals (the alar cartilage and the dorsal nasal cartilage) and one is accessory (the medial accessory nasal cartilage).\n" +
                "-\tThe alar cartilage (Cartilago alaris): is the principal cartilaginous support for the nares. It has C-shaped form with the convex margin being directed medially. This cartilage have a dorsal fibrous tissue attachment to the rostral end of the nasal septum. Each alar cartilage consists of an upper, quadrilateral curved plate, the lamina, and a narrow cornu which curves downwards and outwards. \n" +
                "-\tThe dorsal nasal cartilage (Cartilago nasi lateralis dorsalis): is an expansion formed by the dorsal edge of the septal cartilage ((Cartilago septi nasi) to complete somehow the nasal bone, that it overflows rostrally and on the side. It extends rostrally and contact the lamina of the alar cartilage, with which it can even take some continuity.\n" +
                "-\tThe medial accessory cartilage (Cartilagines nasals accessoriae): Support and strengthen the alar fold.\n");

        List<String> muscles =new ArrayList<>();
        muscles.add("Movements of the external nares are the result of the action of:\n" +
                "o\tCaninus muscle: pulls out the lateral ala of the nostril in the caudal direction.\n" +
                "o\tLevator nasolabialis muscle: combine its action with that of the caninus muscle.\n" +
                "o\tDilator naris apicalis muscle: The most important one, go from one alar cartilage to another, in which it attached to the lamina and the convexity of the cornu.\n" +
                "The lateralis nasi muscle, participate also in enlargement of nasal opening. Being inserted into the cartilaginous extension of the ventral turbinate, it draws the lateral wall of the nasal vestibule outwards and compresses the false nostril.\n");

        List<String> tegument =new ArrayList<>();
        tegument.add("The skin around the nostrils present long tactile hairs as well as the ordinary ones, it is continued around the alae and lines the vestibule in which the skin is often marbled with depigmented spots and it is also provided with sebaceous and sweat glands. In the posterior part of the nasal diverticulum the skin is thin and usually black, and is covered with exceedingly fine hairs; it is provided with numerous sebaceous glands that can give rise to epidermal cysts.");

        List<String> Bloodsupply =new ArrayList<>();
        Bloodsupply.add("The dorsalis nasi and lateralis nasi arteries delegate branches to the nostrils and the rostrum.\n" +
                "There is also a supply from branches provided by the labialis superior and infraorbital arteries. \n" +
                "It is noteworthy that there is an important flow from the incisive trunk, impair, which result from anastomose of the two major palatine arteries.\n");

        List<String> Venousdrainage =new ArrayList<>();
        Venousdrainage.add("are satellite to the arteries, expect for the incisive trunk which has no satellite.");

        List<String> Lymphaticdrainage =new ArrayList<>();
        Lymphaticdrainage.add("the lymphatic vessels drains to the mandibular lymphatic nodes.");

        List<String> Nerves =new ArrayList<>();
        Nerves.add("The sensitive supply is ensured through the infraorbital nerve (a branch of the trigeminal nerve (V)). There is also a supply from the terminal branch of the maxillary nerve. \n" +
                "The motor supply is received through the dorsal buccal branch of the facial nerve (VII).\n");

        listHash.put(listdataheader.get(0),overview);
        listHash.put(listdataheader.get(1),externalfeatures);
        listHash.put(listdataheader.get(2),nasalvestibule);
        listHash.put(listdataheader.get(3),cartilagineousframework);
        listHash.put(listdataheader.get(4),muscles);
        listHash.put(listdataheader.get(5),tegument);
        listHash.put(listdataheader.get(6),Bloodsupply);
        listHash.put(listdataheader.get(7),Venousdrainage);
        listHash.put(listdataheader.get(8),Lymphaticdrainage);
        listHash.put(listdataheader.get(9),Nerves);

    }


}

ExpenableListAdapter

package ma.ac.iav.myapplication;

import android.content.Context;
import android.graphics.Typeface;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.TextView;
import java.util.HashMap;
import java.util.List;

public class ExpendableListAdapter extends BaseExpandableListAdapter {
    private Context context;
    private List<String> listdataheader;
    private HashMap<String, List<String>> listHashMap;

    public ExpendableListAdapter(Context context, List<String> listdataheader, HashMap<String, List<String>> listHashMap) {
        this.context = context;
        this.listdataheader = listdataheader;
        this.listHashMap = listHashMap;
    }

    @Override
    public int getGroupCount() {
        return listdataheader.size();
    }

    @Override
    public int getChildrenCount(int i) {
        return listHashMap.get(listdataheader.get(i)).size();
    }

    @Override
    public Object getGroup(int i) {
        return listdataheader.get(i);
    }

    @Override
    public Object getChild(int i, int i1) {
        return listHashMap.get(listdataheader.get(i)).get(i1);
    }

    @Override
    public long getGroupId(int i) {
        return i;
    }

    @Override
    public long getChildId(int i, int i1) {
        return i1;
    }

    @Override
    public boolean hasStableIds() {
        return false;
    }

    @Override
    public View getGroupView(int i, boolean b, View view, ViewGroup viewGroup) 
{
        String headertitle=(String)getGroup(i);
        if(view==null)
        {
            LayoutInflater inflater=(LayoutInflater) this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            view= inflater.inflate(R.layout.headerlistview,null);
        }
        TextView anatomyListheader=(TextView)view.findViewById(R.id.listheader);
        anatomyListheader.setTypeface(null, Typeface.BOLD);
        anatomyListheader.setText(headertitle);
        return view;
    }

    @Override
    public View getChildView(int i, int i1, boolean b, View view, ViewGroup viewGroup) {
        final String childText=(String)getChild(i,i1);
        if (view==null)
        {
            LayoutInflater inflater=(LayoutInflater) this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            view= inflater.inflate(R.layout.childlistview,null);

        }
        TextView txtlistchild=(TextView)view.findViewById(R.id.textcontent);
        txtlistchild.setText(childText);
        return view;


    }

    @Override
    public boolean isChildSelectable(int i, int i1) {
        return true;
    }
}

Mainactivity.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity"
    >

        <ExpandableListView
            android:id="@+id/acitivitylistview"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            >
        </ExpandableListView>


</RelativeLayout>

Childlistview.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:background="@android:color/transparent"
    >


    <TextView
        android:id="@+id/textcontent"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingBottom="5dp"
        android:paddingLeft="0dp"
        android:paddingRight="0dp"
        android:paddingTop="10dp"
        android:textSize="16dp"
        android:textColor="@android:color/black"

        />
<ImageButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/anatomy"
    android:layout_gravity="center_vertical"/>
</LinearLayout>

headerlistview.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:orientation="vertical"
    android:padding="8dp"
    android:background="@android:color/transparent"
    android:layout_height="match_parent">


    <TextView
        android:id="@+id/listheader"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingLeft="?android:attr/expandableListPreferredItemPaddingLeft"
        android:textSize="18dp"
        android:textColor="@android:color/black"
        android:textStyle="bold"
        android:layout_gravity="center_vertical"

        />

</LinearLayout>

0 个答案:

没有答案